- Install Node.js and npm:
$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - && sudo apt install -y nodejs
- Install MongoDB, following this link MongoDB
- Install [
project]'s dependencies, in the project folder type:$ npm i -s
- Start MongoDB:
$ sudo service mongod start
- Optionally, free the server port which is set to 3000 by default:
$ lsof -i tcp:3000 | grep LISTEN | awk '{print $2}' | xargs kill
- Run the server:
$ chmod u+x server.sh $ ./server.sh
- Optionally, it's possible to chose a port with the command:
$ PORT = typeyourport ./server.sh
Following a brief explanation of the available APIs which can be tested simply using software like postman. The body must be written in JSON format.
-
Users APIs:
- POST to create a new users:
Body:
localhost:3000/users
Result:{"name": "name","password" : "password"}200OK400Request failed! Please check the request403The name is already present in the db
- POST to create a new users:
-
Login APIs:
- GET to login and to get a valid Token:
Body:
localhost:3000/auth/login
Result:{"name": "name","password" : "password"}200OK400Authentication failed! Please check the request format403Username not present in db or Password doesn t match! Please check the request
- GET to login and to get a valid Token:
-
Resource APIs:
All APIs need authentication, after logging, copy the token obtained in the Bearer Token field.
-
POST to create a new resource:
localhost:3000/auth/resource
Body:
{"id": "idResource", "data": [{"field1": "example"}]}The data field is the only one required. Within the data field, up to 10 fields with the name from field1 to fiel10 can be specified. If the id field is not present in the request body will be generated by the server.
Result:
200OK400Resource data can not be empty500Some error occurred while creating the Resource
-
GET to obtain all resources:
localhost:3000/auth/resource
Result:
200OK500Some error occurred while finding the Resources
-
GET to obtain one resources.
localhost:3000/auth/resource/idResource
Result:
200OK500Error retrieving resource with id404Resource not found with id
-
PUT to update one resources:
localhost:3000/auth/resource/idResource
Body:
{"data": [{"field1": "newValue"}]}A resource that has been previously deleted cannot be updated. Result:
200OK500Error updating resource with id404Resource not found with id or already deleted400Resource data can not be empty
-
DELETE to delete one resources:
localhost:3000/auth/resource/idResource
Result:
200OK500Error deleting resource with id404Resource not found with id or already deleted
-
- Run the tests:
$ npm run test