This is a simple server that provides a REST API for managing todos.
Start it by running
npm start
from command line.
Todos are stored in todos-db.json
. To reset the database, revert changes to this file by using git:
git checkout -- todos-db.json
or
git checkout -- server/todos-db.json
if you're in the root folder.
Get all todos.
URL : localhost:3000/todos
Method : GET
Code : 200 OK
Content examples
List with one active and one completed todo:
[
{
"id": 123,
"text": "Go running",
"isDone": false
},
{
"id": 456,
"text": "Buy milk",
"isDone": true
}
]
You can filter the todo list by using query
parameter:
/todos?query=active
: only return active (i.e."isDone"
is false) todos/todos?query=complete
: only return completed (i.e."isDone"
is true) todos/todos?query=all
: return the whole list; this is equal to omitting the query parameter
URL : localhost:3000/todos
Method : POST
Request Body :
The newly created todo:
{
"text": "Follow trainers on Twitter",
"isDone": false
}
The id will be created by the server.
Code : 201 Created
Content examples
The newly created todo:
{
"id": 789,
"text": "Follow trainers on Twitter",
"isDone": false
}
URL : localhost:3000/todos/:id
(where :id
is the id
value of the todo to be edited)
Method : PUT
Request Body :
The edited todo.
Example :
Set todo with id 789 to done:
PUT localhost:3000/todos/789
{
"text": "Follow trainers on Twitter",
"isDone": true
}
Code : 200 OK
Content examples
The edited todo:
{
"id": 789,
"text": "Follow trainers on Twitter",
"isDone": true
}
URL : localhost:3000/todos/:id
(where :id
is the id
value of the todo to be deleted)
Method : DELETE
Code : 200 OK