Skip to content

Latest commit

 

History

History
154 lines (100 loc) · 2.13 KB

README.md

File metadata and controls

154 lines (100 loc) · 2.13 KB

Todo Server

This is a simple server that provides a REST API for managing todos.

Start it by running

npm start

from command line.

Reset Database

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.

API Documentation

Retrieve Todos

Get all todos.

URL : localhost:3000/todos

Method : GET

Success Response

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
  }
]

Filtering Todos

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

Create New Todo

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.

Success Response

Code : 201 Created

Content examples

The newly created todo:

{
  "id": 789,
  "text": "Follow trainers on Twitter",
  "isDone": false
}

Edit Todo

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
}

Success Response

Code : 200 OK

Content examples

The edited todo:

{
  "id": 789,
  "text": "Follow trainers on Twitter",
  "isDone": true
}

Delete Todo

URL : localhost:3000/todos/:id (where :id is the id value of the todo to be deleted)

Method : DELETE

Success Response

Code : 200 OK