Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Latest commit

 

History

History
155 lines (101 loc) · 2.08 KB

README.md

File metadata and controls

155 lines (101 loc) · 2.08 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 parameters:

Todos Request-URL
Done http://localhost:3000/todos?isDone=1
Open http://localhost:3000/todos?isDone=0

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