RESTful API Designed in Node.js for a very simple TODO application.
- Requirements
- Installation
- Schema
- Authentication
- Root End-Point
- Core Resources
- Documentation
- Request & Response Examples
- node & npm
- MongoDB: Make sure you have your own local or remote MongoDB database URI configured in
credentials/mongo.js
- PostMan
- Clone the repository:
git clone git@github.com:toslimarif/todo-api.git
- Install the application:
npm install
- Place your own MongoDB URI in
credentials/mongo.js
- Start the server:
node server.js
ornode .
- Open PostMan and make a
GET
request tohttp://localhost:3000/api/info/
- All API access is over HTTP, and accessed from
http://localhost:3000/api/v1
. - All data is sent and received as JSON.
- Blank fields are included as
null
instead of being omitted. - All timestamps return in ISO 8601 format:
YYYY-MM-DDTHH:MM:SSZ
There are no authentication implemented yet. So, all the end-points are open.
http://localhost:3000/api/v1
Todo
object represents snapshot of a specific Todo with a unique Id. You can retrieve it to see details about the Todo.
{
title: {
type: String,
required: true
},
description: {
type: String,
required: true,
default: 'N/A'
},
onDate: {
type: Date,
required: true,
default: Date.now
},
cardColor: {
type: String,
required: true,
default: '#cddc39'
},
isCompleted: {
type: Boolean,
required: true,
default: false
},
timestamps: {
createdOn: {
type: Date,
required: true,
default: Date.now
},
modifiedOn: {
type: Date,
required: true,
default: Date.now
},
completedOn: {
type: Date,
default: null
}
}
}
Method | End-Point | Description |
---|---|---|
GET |
/todo |
List all todos |
POST |
/todo |
Create a new todo |
GET |
/todo/:id |
Fetch a specific todo |
PUT |
/todo/:id |
Edit existing todo |
PATCH |
/todo/:id |
Mark an existing todo as complete |
DELETE |
/todo/:id |
Delete existing todo |
https://documenter.getpostman.com/view/8474302/SVfGyBSu
To get the list of all todos
http://localhost:3000/api/v1/todo
N/A
N/A
{
"status": "Success",
"message": "Todos Fetched Successfully!",
"todos": [
{
"timestamps": {
"completedOn": null,
"createdOn": "2019-08-16T17:07:07.171Z",
"modifiedOn": "2019-08-16T17:07:07.171Z"
},
"description": "Write documentation for Todo API",
"cardColor": "#ff7043",
"isCompleted": false,
"_id": "5d56e2bbc2a36326a0a57c19",
"title": "Write Documentation",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0
},
{
"timestamps": {
"completedOn": null,
"createdOn": "2019-08-16T17:08:48.376Z",
"modifiedOn": "2019-08-16T17:08:48.376Z"
},
"description": "Write Test-Cases for Todo API",
"cardColor": "#4dd0e1",
"isCompleted": false,
"_id": "5d56e320c2a36326a0a57c1a",
"title": "Write Test-Cases",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0
}
],
"todoCount": 2
}
To get a specific todo
http://localhost:3000/api/v1/todo/{{TODO_ID}}
{{TODO_ID}}
N/A
{
"status": "Success",
"message": "Todo Fetched Successfully!",
"todo": {
"timestamps": {
"completedOn": null,
"createdOn": "2019-08-16T17:07:07.171Z",
"modifiedOn": "2019-08-16T17:07:07.171Z"
},
"description": "Write documentation for Todo API",
"cardColor": "#ff7043",
"isCompleted": false,
"_id": "5d56e2bbc2a36326a0a57c19",
"title": "Write Documentation",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0
}
}
To create a new todo
http://localhost:3000/api/v1/todo
N/A
{
"title": "Write Test-Cases",
"description": "Write Test-Cases for Todo API",
"onDate": "2019-08-16T15:47:30.889Z",
"cardColor": "#4dd0e1"
}
{
"status": "Success",
"message": "Todo Created SuccessFully!",
"todo": {
"timestamps": {
"completedOn": null,
"createdOn": "2019-08-16T17:08:48.376Z",
"modifiedOn": "2019-08-16T17:08:48.376Z"
},
"description": "Write Test-Cases for Todo API",
"cardColor": "#4dd0e1",
"isCompleted": false,
"_id": "5d56e320c2a36326a0a57c1a",
"title": "Write Test-Cases",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0,
"todoId": "5d56e320c2a36326a0a57c1a"
}
}
To edit an existing todo
http://localhost:3000/api/v1/todo/{{TODO_ID}}
{{TODO_ID}}
{
"title": "UPDATED: Write Documentation",
"description": "UPDATED: Write documentation for Todo API"
}
{
"status": "Success",
"message": "Todo Updated Successfully!",
"todo": {
"timestamps": {
"completedOn": "2019-08-16T18:10:33.224Z",
"createdOn": "2019-08-16T17:07:07.171Z",
"modifiedOn": "2019-08-16T18:14:13.499Z"
},
"description": "UPDATED: Write documentation for Todo API",
"cardColor": "#ff7043",
"isCompleted": true,
"_id": "5d56e2bbc2a36326a0a57c19",
"title": "UPDATED: Write Documentation",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0
}
}
To mark a todo as Complete
http://localhost:3000/api/v1/todo/{{TODO_ID}}
{{TODO_ID}}
N/A
{
"status": "Success",
"message": "Todo Marked as Completed!",
"todo": {
"timestamps": {
"completedOn": "2019-08-16T18:10:33.224Z",
"createdOn": "2019-08-16T17:07:07.171Z",
"modifiedOn": "2019-08-16T18:10:33.224Z"
},
"description": "Write documentation for Todo API",
"cardColor": "#ff7043",
"isCompleted": true,
"_id": "5d56e2bbc2a36326a0a57c19",
"title": "Write Documentation",
"onDate": "2019-08-16T15:47:30.889Z",
"__v": 0
}
}
To delete an existing todo
http://localhost:3000/api/v1/todo/{{TODO_ID}}
{{TODO_ID}}
N/A
{
"status": "Success",
"message": "Todo Deleted Successfully!"
}