This API is publicly available at https://task-manager-api-ahmad.herokuapp.com, you can test it through postman or implement it in a Web App.
git clone https://github.com/w28ahmad/Task-Manager-API.git && cd Task-Manager-API
You are going to need to create a config folder containing a dev.env file. This file will contain all the environment variables used in this REST API.
mkdir config & cd config & touch dev.env
In the dev.env file you are going to need the following enviroment variables:
- PORT Can me anything you prefer, I usually go for 3000
- SENDGRID_API_KEY This is for the automated emails welcoming the user when they create an account or saying goodbye when they delete their account. You can choose to ignore this environment variable everything should still work fine.
- JWT_SECRET This could be ay set of characters (without spaces)
- MONGODB_URL=mongodb://127.0.0.1:27017/task-manager-api You going to have to setup and connect to local mongoDB instance for this to work
Now you can run the REST API
npm run dev
Feel free to test any of the routes using Postman
- Create a User Account
- Login to your user accout
- Create a Task
- Update a Task
- Delete a Task
- Read a Task
- Update a User
- Delete a User
- Read a Task
- Read your User Details
- Logout
Create an account to hold your tasks details. These user details are going to securely stored in a MongoDB Database.
POST: https://task-manager-api-ahmad.herokuapp.com/users
{
"name": "Wahab Ahmad",
"email": "email@gmail.com",
"password": "testing123"
}
If you create an account you are automatically logged in. However, if you need to login you use the folloring route.
POST: https://task-manager-api-ahmad.herokuapp.com/users/login
{
"email": "dan@gmail.ca",
"password": "testing123"
}
To add a task that you have to complete, use the following route:
POST: https://task-manager-api-ahmad.herokuapp.com/tasks
{
"discription": "Finish the Task Manager REST API",
"completed" : false
}
Note: If you don't specify completed, it will be set to false by default
If you need to change/update a task you use the following route:
PATCH: https://task-manager-api-ahmad.herokuapp.com/tasks/{task_id}
{
"discription": "Finish the Task Manager REST API",
"completed" : true
}
Note: Setting that task to true, you don't need to specify discription, I did it for the expample
If you need to delete a task you can use the following route:
DELETE: https://task-manager-api-ahmad.herokuapp.com/tasks/{task_id}
If you want to read a task(s) use the following route:
GET: https://task-manager-api-ahmad.herokuapp.com/tasks
Here I have added parameters to filter, paginate and sort the results.
GET: https://task-manager-api-ahmad.herokuapp.com/tasks/skip=3&limit=2
Here we are limiting the search result to tasks and skip sections the tasks
GET: https://task-manager-api-ahmad.herokuapp.com/tasks?sortBy=createdAt:desc
This sorts the tasks in order of recency according to the timestamp
GET: https://task-manager-api-ahmad.herokuapp.com/tasks?sortBy=createdAt:asc
This sorts the tasks placing the the oldest tasks first
GET: https://task-manager-api-ahmad.herokuapp.com/tasks?completed=false
This filters out the uncompleted tasks. Likewise setting completed to true will filter out the completed tasks. We can use all the methords together like so:
GET: https://task-manager-api-ahmad.herokuapp.com/tasks?skip=3&limit=2&completed=false&sortBy=createdAt:desc
You are able to update the details of a user using:
PATCH: https://task-manager-api-ahmad.herokuapp.com/users/me
{
"name": "Wab",
"email": "myemail@gmail.com",
"password": "testing1234"
}
You are able to delete your user and his/her tasks using the following route:
Delete: https://task-manager-api-ahmad.herokuapp.com/users/me
You are able to read your user profile information through the following route:
GET: https://task-manager-api-ahmad.herokuapp.com/users/me
{
"age": 0,
"_id": "5cdf49eaa7135d00178bd58f",
"name": "Wahab Ahmad",
"email": "wab@gmail.com",
"createdAt": "2019-05-17T23:55:22.608Z",
"updatedAt": "2019-05-17T23:55:23.455Z",
"__v": 1
}
Logout from your account using the following route:
POST: https://task-manager-api-ahmad.herokuapp.com/users/me
I was interested in how to upload files so I created a route for uploading images:
POST: https://task-manager-api-ahmad.herokuapp.com/users/me/avatar
You can delete your avatar using the following route:
DELETE: https://task-manager-api-ahmad.herokuapp.com/users/me/avatar
The image is going to be resized and cropped, and then the binary will be stored in the Database.
- Express
- Multer
- Sharp
- Validator
- Mongoose
- Mongodb
- jsonwebtoken
- bcryptjs
- @sendgrid/mail
In the future, I hope to use React and Angular to create a front end that interacts with this REST API.