You have to install the following dependencies to run this API.
Install express
npm install -S express
Install mongoose to work with MongoDB
npm i -S mongoose
Install dotenv to read you .env file
npm install dotenv --save
Install bcrypt, jsonwebtoekn and express-jwt for authentication and authorization
npm i -S bcrypt jsonwebtoken express-jwt
The applition is running in port 3000 with the following methods:
Create a .env file and add the following variables
MONGO_URI: connection string to MongoDBSECRET: secret to sign and validate jwt
- Register a new user.
Method: GET
http://localhost:3000/register
- Login with an existing user.
Method: GET
http://localhost:3000/login
These methods need a JsonWebToken generated by login method and send it with the next Header.
{
"Authorization": Bearer {jwt}
}
- List all users
Method: GET
http://localhost:3000/users
- Get a specific user
Method: GET
http://localhost:3000/users/{user_id}
- Create new user
Method: POST
http://localhost:3000/users
Body
{
"name": "String",
"lastName": "String"
}
- Update user
Method: PUT
http://localhost:3000/users/{user_id}
Body
{
"name": "String",
"lastName": "String"
}
- Delete user
Method: DELETE
http://localhost:3000/users/{user_id}