Skip to content

Commit a3e2d24

Browse files
committed
Improved documentation.
1 parent 6432828 commit a3e2d24

14 files changed

Lines changed: 200 additions & 149 deletions

README.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,94 @@ The UNIWeb API provides:
1919

2020
An example reference client for the Uniweb API is written in PHP and can be installed via [Composer](https://getcomposer.org/).
2121

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
2335
$ composer require proximify/uniweb-api
2436
```
2537

2638
### Testing
2739

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+
<p align="center">
45+
<img src="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+
<p align="center">
51+
<img src="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+
<p align="center">
57+
<img src="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`.
2999
30100
```zsh
31-
$ cd vendor/proximify/uniweb-api/www/ && php -S localhost:8000
101+
$ cd www && php -S localhost:8000
32102
```
33103

34104
While the PHP web server is running, the URL `http://localhost:8000` should display the website.
35105

106+
<p align="center">
107+
<img src="docs/assets/api-queries.png" width="600px" alt="uniweb API logo" style="border:1px solid #ddd">
108+
</p>
109+
36110
Alternatively, it is possible to test the predefined queries from the command line using composer and the `query` script.
37111

38112
```bash

composer.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/admin_rbac.png

41.2 KB
Loading

docs/assets/api-modal.png

105 KB
Loading

docs/assets/api-queries.png

164 KB
Loading

docs/assets/api-screen.png

130 KB
Loading

docs/assets/api-secret.png

99.5 KB
Loading

docs/assets/api_cv_sections.png

79.7 KB
Loading

docs/assets/api_fields.png

18.8 KB
Loading
28.3 KB
Loading

0 commit comments

Comments
 (0)