A Backend RESTful API to store and organize your tasks. It is a secure API because it does not let other users acess your tasks by authenticate all users.
Documentaรงรฃo em Portuguรชs do Brasil
- Node
- Express
- MongoDB
- Mongoose
- Nodemon
- Validator
- Bcrypt
- JSON Web Token
- SendGrid
- Jest
- SuperTest
- Multer
Observation: This application is deployed in Heroku. So if you want to use it from Heroku you can skip the setup part.
- Setup (Optional)
- All Endpoints
- How to use users API Endpoints
- Create new user
- Login an existing user
- Update user informations
- Get profile from a logged user
- Get user profile by ID
- Upload logged user avatar
- Get the avatar from a logged user
- Get the user avatar profile by ID
- Logout a user
- Logout a user from all sessions
- Delete a logged user avatar
- Delete a logged user
- How to use tasks API Endpoints
- Author
Node
Mongodb
Clone the project:
$ git clone https://github.com/Lukazovic/node-task-manager-api.git
Go into the project root folder:
$ cd node-task-manager-api
Install the projects modules:
$ npm install
Observation: You will need to setup some environment configs in order to start the server or run the tests.
First create a config folder at the root of the project:
$ mkdir config
To setup the server environment: You will have to create a file at ./config
called dev.env
and configure as the example bellow:
PORT=<Port-Number>
SENDGRID_API_KEY=<Sendgrid-Api-Key>
MONGODB_URL=mongodb://127.0.0.1:27017/<Data-Base-Name>
JWT_SECRET=<Secret-JWT>
- Port-Number: A port number to acess the server
(example: PORT=3000)
; - Sendgrid-Api-Key: A key provided by SendGrid so you can send emails directly from the application;
- Data-Base-Name: A name to the database
(example: node-task-manager-api)
; - Secret-JWT: A secret word to generate the tokens for the API
(example: mysecretword)
.
To setup the tests environment: You will have to create a file at ./config
called test.env
and configure as the example above EXCEPT the Data-Base-Name where you should change the name (example: node-task-manager-test-api)
;
$ npm run test
To run the API (in the project folder):
$ npm run start
Access in: localhost:Port-Number
- POST:
/users
- Create new user - POST:
/users/login
- Login an existing user - PATCH:
/users/me
- Update user informations - GET :
/users/me
- Get profile from a logged user - GET:
/users/<id>
- Get user profile by ID - POST:
/users/me/avatar
- Upload logged user avatar - GET:
/users/me/avatar
- Get the avatar from a logged user - GET:
/users/<id>/avatar
- Get the user avatar profile by ID - POST:
/users/logout
- Logout a user - POST:
/users/logoutAll
- Logout a user from all sessions - DELETE:
/users/me/avatar
- Delete a logged user avatar - DELETE:
/users/me
- Delete a logged user
- POST:
/tasks
- Create new task to a logged user - GET:
/users
- Get all tasks from a logged user - GET :
/tasks/<id>
- Get task by ID from a logged user - PATCH:
/tasks/<id>
- Update task by ID from a logged user - DELETE:
/tasks/<id>
- Delete task by ID from a logged user
- POST:
/users
Paramether | Description | Type | Required |
---|---|---|---|
name | User's name | String | True |
age | User's age | Integer | False |
User's email | String | True | |
password | User's password | String | True |
Password length has to be greater than 7 and can not contain the word
password
{
"name": "User Test",
"age": 18,
"email": "test@email.com",
"password": "idontknow"
}
As response you will receive a token so you will be able to use it to authenticate the user when it needed As soon as the user is created the application will send an email to the user's email
{
"user": {
"age": 18,
"_id": "5e6e0117bb997d0017c94f0d",
"name": "User Test",
"email": "test@email.com",
"createdAt": "2020-03-15T10:19:03.027Z",
"updatedAt": "2020-03-15T10:19:03.076Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTZlMDExN2JiOTk3ZDAwMTdjOTRmMGQiLCJpYXQiOjE1ODQyNjc1NDN9.aAvvkMcEaSeQxKyu6wDQXfQ1z4hM9zn1myJT8Iw689U"
}
- POST:
/users/login
https://task-manager-node-rest-api.herokuapp.com/users/login
Paramether | Description | Type | Required |
---|---|---|---|
User's email | String | True | |
password | User's password | String | True |
{
"email": "test@email.com",
"password": "idontknow"
}
As response you will receive a token so you will be able to use it to authenticate the user when it needed
{
"user": {
"age": 18,
"_id": "5e6e0117bb997d0017c94f0d",
"name": "User Test",
"email": "test@email.com",
"createdAt": "2020-03-15T10:19:03.027Z",
"updatedAt": "2020-03-15T10:29:26.514Z"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ZTZlMDExN2JiOTk3ZDAwMTdjOTRmMGQiLCJpYXQiOjE1ODQyNjgxNjZ9.MSTXSv6RHlZCSkc2HlMKHhr9vHS-4HV7NPHrG4JBkKs"
}
- PATCH:
/users/me
Paramether | Description | Type | Required |
---|---|---|---|
name | User's name | String | False |
age | User's age | Integer | False |
User's email | String | False | |
password | User's password | String | False |
Authorization | Session user's Token | Bearer Token | True |
{
"name": "User Test",
"age": 18,
"email": "test@email.com",
"password": "idontknow"
}
- GET:
/users/me
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- GET:
/users/<id>
<id> is the identifier of the user
https://task-manager-node-rest-api.herokuapp.com/users/5e6e0117bb997d0017c94f0d
Paramether | Description | Type |
---|---|---|
_id | User's ID | String |
- POST:
/users/me/avatar
https://task-manager-node-rest-api.herokuapp.com/users/me/avatar
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
avatar | User's avatar | Form-Data | True |
- GET:
/users/me/avatar
https://task-manager-node-rest-api.herokuapp.com/users/me/avatar
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- GET:
/users/<id>/avatar
<id> is the identifier of the user
https://task-manager-node-rest-api.herokuapp.com/users/5e6e0117bb997d0017c94f0d/avatar
Paramether | Description | Type |
---|---|---|
_id | User's ID | String |
- POST:
/users/logout
https://task-manager-node-rest-api.herokuapp.com/users/logout
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- POST:
/users/logoutAll
https://task-manager-node-rest-api.herokuapp.com/users/logoutAll
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- DELETE:
/users/me/avatar
https://task-manager-node-rest-api.herokuapp.com/users/me/avatar
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- DELETE:
/users/me
Paramether | Description | Type | Required |
---|---|---|---|
Authorization | Session user's Token | Bearer Token | True |
- POST:
/tasks
Paramether | Description | Type | Required |
---|---|---|---|
description | Tak's description | String | True |
completed | Task's situation | Boolean | False |
{
"description": "Do a task",
"completed": false
}
{
"completed": false,
"_id": "5e6e68914934ce0017892730",
"description": "Do a task",
"owner": "5e6e0117bb997d0017c94f0d",
"createdAt": "2020-03-15T17:40:33.445Z",
"updatedAt": "2020-03-15T17:40:33.445Z",
"__v": 0
}
- GET:
/tasks
You can sort tasks by adding ?sortBy=completed:desc
to the URL in order to the GET all tasks sorted by not completed.
You can also GET all tasks sorted by completed by addind ?sortBy=completed:asc
to the URL.
You can get a limit of tasks by adding ?limit=10
to the URL so you will get 10 tasks.
You can skip the firsts tasks by adding ?skip=10
to the URL. So you can use pagination by limiting the tasks you get by each request and skiping some tasks by adding ?limit=10&skip=10
- Sorting tasks by completed:
https://task-manager-node-rest-api.herokuapp.com/tasks?sortBy=completed:asc
- Sorting tasks by completed:
https://task-manager-node-rest-api.herokuapp.com/tasks?sortBy=completed:desc
- Get only the first 10 tasks:
https://task-manager-node-rest-api.herokuapp.com/tasks?limit=10
- Skip the first 10 tasks:
https://task-manager-node-rest-api.herokuapp.com/tasks?skip=10
- Pagination - Getting pages with 10 tasks per page.
Page 1: https://task-manager-node-rest-api.herokuapp.com/tasks?limit=10&skip=10
Page 2: https://task-manager-node-rest-api.herokuapp.com/tasks?limit=10&skip=20
Page 3: https://task-manager-node-rest-api.herokuapp.com/tasks?limit=10&skip=30
- All togheter - Getting the second page with 10 tasks by page and sorting by not completed ones.
https://task-manager-node-rest-api.herokuapp.com/tasks?sortBy=completed:desc&limit=10&skip=10
GET : /tasks/<id>
- <id> is the identifier of the user
https://task-manager-node-rest-api.herokuapp.com/tasks/5e6e0117bb997d0017c94f0d
- PATCH:
/tasks/<id>
<id> is the identifier of the task you want to update
https://task-manager-node-rest-api.herokuapp.com/tasks/5e6e0117bb997d0017c94f0d
Paramether | Description | Type | Required |
---|---|---|---|
description | Tak's description | String | False |
completed | Task's situation | Boolean | False |
{
"description": "Do a task",
"completed": true
}
- PATCH:
/tasks/<id>
<id> is the identifier of the task you want to delete
https://task-manager-node-rest-api.herokuapp.com/tasks/5e6e0117bb997d0017c94f0d
Lucas Vieira ๐ป |