You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+77-3Lines changed: 77 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,20 +19,94 @@ The UNIWeb API provides:
19
19
20
20
An example reference client for the Uniweb API is written in PHP and can be installed via [Composer](https://getcomposer.org/).
21
21
22
-
```zsh
22
+
It is common to download the client to run local tests and use the client as a reference. Other clients can be developed in different language since all the is required is the ability to send HTTP requests.
23
+
24
+
To experiment with the API client, one can simply create a project with it by running the command
25
+
26
+
```bash
27
+
$ composer create-project proximify/uniweb-api
28
+
```
29
+
30
+
The advantage of creating a project like that is that the `composer.json` in it already defines a CLI `query` script for [testing](#testing).
31
+
32
+
The API client can also be added as a dependency of another project via
33
+
34
+
```bash
23
35
$ composer require proximify/uniweb-api
24
36
```
25
37
26
38
### Testing
27
39
28
-
A simple way to test the client is to use the PHP built-in web server. To launch the built-in web server, change directory to the `www` folder within the website project, and start the web server there.
40
+
#### Creating the credentials
41
+
42
+
In your UNIWeb instance, go to the Administration screen and select the API section.
43
+
44
+
<palign="center">
45
+
<imgsrc="docs/assets/api-screen.png"width="600px"alt="uniweb API logo">
46
+
</p>
47
+
48
+
Click on the "Create a client" button, enter a name for your API client, and save it.
49
+
50
+
<palign="center">
51
+
<imgsrc="docs/assets/api-modal.png"width="600px"alt="uniweb API logo">
52
+
</p>
53
+
54
+
Once created, look for the client in the list of clients and click on its "View" button to find out the secret that was created for the client.
55
+
56
+
<palign="center">
57
+
<imgsrc="docs/assets/api-secret.png"width="600px"alt="uniweb API logo">
58
+
</p>
59
+
60
+
> Note: the permissions of the client are those of the user that created the client.
61
+
62
+
To connect to UNIWeb via its API you will need the URL of the instance, the client name, and the client secret.
63
+
64
+
#### Using the reference UniwebClient class
65
+
66
+
The constructor of the **UniwebClient** class expects an array with credentials of the form
67
+
68
+
```php
69
+
$credentials = [
70
+
"clientName" => "",
71
+
"clientSecret" => "",
72
+
"homepage" => ""
73
+
]
74
+
```
75
+
76
+
When running tests, the credentials can be defined in a json file named `credentials.json` and place within the `settings` folder. For security, `settings/credentials.json` should be added to `.gitignore` to avoid committing the secret by accident.
77
+
78
+
### Running the sample queries
79
+
80
+
The `uniweb-api` project includes a `queries` folder with code representing different use cases of the **UniwebClient** class to perform common types of API requests.
81
+
82
+
If the project was created with `composer create-project`, then the root folder will also include a `www` folder with a simple script to generate a home webpage for running the sample queries. In addition, the `composer.json` file defines a Composer command that can be used to run the queries from a terminal.
83
+
84
+
To run the sample queries you will need to set the API credentials in `settings/credentials.json`
85
+
86
+
```php
87
+
{
88
+
"clientName": "",
89
+
"clientSecret": "",
90
+
"homepage": ""
91
+
}
92
+
```
93
+
94
+
The `.gitignore` file of the uniweb-api project already includes the command to exclude that file from the repository. But if you use the project as a dependency of another project, make sure that the `credentials.json` is ignored in it as well.
95
+
96
+
A simple way to test the client is to use the PHP built-in web server. To launch the built-in web server, change directory to the `www` folder within the uniweb-api project, and start the web server there.
97
+
98
+
> Note: If the project is a dependency within a parent project, you first must to go to the root folder `vendor/proximify/uniweb-api`.
0 commit comments