Test Assignment for frontend developer API documentation version 1
https://test-assignment-api.goodsoft.com.ua
/token
Get token for user registration.
Method returns a token that is required to register a new user. The token is valid for 40 minutes and can be used for only one request. For the next registration, you will need to get a new one.
Example of method url:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/token ```
Example curl sh:
```sh $curl https://test-assignment-api.goodsoft.com.ua/api/v1/token ```
Example javascript:
```js fetch('https://test-assignment-api.goodsoft.com.ua/api/v1/token') .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); }) .catch(function(error) { // proccess network errors }); ```
/users
Users pagination
Returns users data from a database divided into pages and sorted by ID in the ascending order. You can specify the parameters such as **count**, **offset** and **page**, which correspond to the number of users on the page, missing record number and page number. If you specify the **offset** parameter, the **page** parameter will be ignored.
To navigate through the pages, you can use the links in the server's response: next_link to go to the next page and prev_link to return to the previous page. If the next or previous page does not exist, the next_link/prev_link parameter will be set to null
Example of method url:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/users?page=1&count=5 ```
Example curl sh:
```sh $curl https://test-assignment-api.goodsoft.com.ua/api/v1/users?page=1&count=5 ```
Example javascript:
```js fetch('https://test-assignment-api.goodsoft.com.ua/api/v1/users?page=1&count=5') .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); if(data.success) { // process success response } else { // proccess server errors } }) ```
User registration request.
All fields are **required**
- name - user name, should be 2-60 characters
- email - user email, must be a valid email according to RFC2822
- phone - user phone number, should start with code of Ukraine +380
- position_id - user position id. You can get list of all positions with their IDs using the API method GET api/v1/positions
- photo - user photo should be jpg/jpeg image, with resolution at least 70x70px and size must not exceed 5MB.
Example of method url:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/users ```
Example curl sh:
```sh $curl --form "[email protected]/photo.jpg;" \ --form name=Jhon \ --form [email protected] \ --form phone=+380955388485 \ --form position_id=2 \ https://test-assignment-api.goodsoft.com.ua/api/v1/users ```
Example javascript:
```js var formData = new FormData(); // file from input type='file' var fileField = document.querySelector('input[type="file"]'); formData.append('position_id', 2); formData.append('name', 'Jhon'); formData.append('email', '[email protected]'); formData.append('phone', '+380955388485'); formData.append('photo', fileField.files[0]);
fetch('https://test-assignment-api.goodsoft.com.ua/api/v1/users', { method: 'POST', body: formData, headers: { 'Token': token, // get token with GET api/v1/token method }, }) .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); if(data.success) { // process success response } else { // proccess server errors } }) .catch(function(error) { // proccess network errors });
/users/{id}
##Get user by id Return information about user by his id. This method can be used to obtain a specific user for the site header.
Example of method url:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/users/1 ```
Example curl sh:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/users/1 ```
Example javascript:
```js fetch('https://test-assignment-api.goodsoft.com.ua/api/v1/users/1') .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); if(data.success) { // process success response } else { // proccess server errors } }) ```
/positions
Get users positions
Returns a list of all available users positions.
Example of method url:
```sh https://test-assignment-api.goodsoft.com.ua/api/v1/positions ```
Example curl sh:
```sh $curl https://test-assignment-api.goodsoft.com.ua/api/v1/positions ``` ### Example javascript:
```js fetch('https://test-assignment-api.goodsoft.com.ua/api/v1/positions') .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); // process success response }) ```