The goal
We are going to build, piece by piece, a complete REST API to manage one resource: tasks (a to-do). When you finish you will have assembled a realistic service out of small, testable functions, just like in a professional project.
The resource: a task
Each task is a simple object:
{ id: 1, title: "Study Node", done: false }
id: unique identifier, numeric and incremental.title: required text (provided by the client).done: whether it is completed. New tasks are born withdone: false.
The REST routes
REST models the resource and uses the HTTP method for the action. For tasks:
| Method | Route | Action |
|---|---|---|
| GET | /tasks |
list (with optional filter) |
| GET | /tasks/:id |
view one |
| POST | /tasks |
create |
| PUT | /tasks/:id |
update |
| DELETE | /tasks/:id |
delete |
Each operation responds with a coherent status code: 200 (OK),
201 (created), 400 (invalid input), 401 (not authenticated),
404 (not found).