Skip to content

Latest commit

 

History

History
59 lines (40 loc) · 2.26 KB

File metadata and controls

59 lines (40 loc) · 2.26 KB

Task API

A small in-memory to-do list API built with Node.js and Express — the FlyRank Backend Track Week 2 assignment (Build your first CRUD API).

What this is

A REST API that lets you create, read, update and delete tasks. Data lives only in memory (a plain array in index.js) — it resets whenever the server restarts. There is no database yet; that's next week.

How to run it

npm install
npm start

The server starts on http://localhost:3000.

Endpoints

Method Path Meaning
GET / API info
GET /health Health check
GET /tasks List all tasks (supports ?done=true|false and ?search=text)
GET /tasks/:id Get a single task
POST /tasks Create a task ({ "title": "..." })
PUT /tasks/:id Update a task's title and/or done
DELETE /tasks/:id Delete a task
GET /stats Task counts: { total, done, open }
POST /reset Restore the 3 seed tasks

Status codes: 200 reads, 201 create, 204 delete, 400 invalid body, 404 unknown id — every error comes back as { "error": "..." }.

Swagger UI

Interactive docs are served at http://localhost:3000/docs, generated from openapi.json. Use "Try it out" to run the full CRUD cycle without curl.

Example: curl

$ curl -i -X POST http://localhost:3000/tasks -H "Content-Type: application/json" -d '{"title":"Buy milk"}'
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{"id":4,"title":"Buy milk","done":false}

Extras

Beyond the required CRUD cycle:

  • Filtering: GET /tasks?done=true returns only finished tasks.
  • Search: GET /tasks?search=milk returns tasks whose title contains the word (case-insensitive).
  • Stats: GET /stats returns { total, done, open }.
  • Reset: POST /reset restores the 3 seed tasks — handy after a demo or the mortality experiment below.

The mortality experiment

Create a task, restart the server, then GET /tasks again — the new task is gone; only the 3 seed tasks remain. Data lives in a JavaScript array in the server's memory, so it only survives as long as the Node process does. This is exactly why real apps need a database: anything you want to persist across restarts has to live outside the process.