Restful API developed with Node.js, Express.js and MongoDB and secured with JSON Web Token.
https://jb-todo-api.herokuapp.com/v1
| Path | Method | Description |
|---|---|---|
| /tasks | post | Creates a new task |
| /tasks | get | Retrieve all tasks |
| /tasks/:id | get | Retrieve a task for a given id |
| /tasks/filter/:filter | get | Retrieve all tasks for a given keyword |
| /tasks/:id | put | Updates a task for a given id |
| /tasks/:id | delete | Deletes a task for a given id |
For replicating this demo the following software is required:
- Download and install Node.js and npm.
- Download and install MongoDB. For this demo a Docker container was used.
- (Optional) Download and install Postman. Recommended for testing purposes.
- Clone the repository:
git clone https://github.com/JuanBalceda/todo-app.git - Install all dependencies
npm install - Configure the
/config/env.js - Start the server
node startornpm restart(nodemon) - Test the API with Postman.
The chosen endpoint will perform certain action if the username is specified on the jwt payload.
Example payload data:
{
"username": "juanbalceda",
"iat": 1543438543
}For more information about how jwt works, visit: https://jwt.io/
https://jb-todo-api.herokuapp.com/v1/tasks
{
"done":false,
"_id":"5bfe89bf4d5f760016e4723a",
"task":"Test API through UI",
"who":"juanbalceda",
"dueDate":"2018-11-29T00:00:00.000Z",
"created":"2018-11-28T12:27:43.938Z",
"__v":0
}For POST method, the only required field on the json body is task, who and created are set by default, dueDate is optional.
{
"done":false,
"task":"Test API through UI",
"who":"juanbalceda",
"dueDate":"2018-11-29T00:00:00.000Z",
"created":"2018-11-28T12:27:43.938Z"
}$ docker container run -p 27017:27017 --name mongodb -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=123456 -d mongo:latest
$ docker exec -it mongodb bash# On container shell
$ mongo --authenticationDatabase admin -u admin -p 123456
# On mongodb shell
use todo_app
db.createUser(
{
user: "rhtest",
pwd: "123456",
roles: [
{ role: "readWrite", db: "todo_app" }
]
}
)This app is MIT licensed.
