Add POST /todos and DELETE /todos/:id with mutable in-memory store #5

Open
opened 2026-05-12 06:54:31 +00:00 by danny8632 · 1 comment
Owner

Goal

Refactor the hardcoded todos array in index.js into a mutable in-memory array, then add POST /todos (create) and DELETE /todos/:id (delete) endpoints. Base work on the agent/issue-3 branch. POST must accept a JSON body with a title field, assign a unique numeric id, set done: false, and return the created item with HTTP 201. DELETE must return 204 on success and 404 when the id does not exist. No database required.

Done criteria

  • index.js declares a mutable let todos = [...] (or equivalent) instead of a hardcoded const
  • POST /todos with body {"title":"buy milk"} returns HTTP 201 and JSON containing id, title, and done: false
  • Two successive POST requests produce items with distinct numeric ids
  • DELETE /todos/:id for a valid id returns HTTP 204 and the item is absent from a subsequent GET /todos
  • DELETE /todos/:id for a non-existent id returns HTTP 404
  • GET /healthz still returns HTTP 200

Hints

Express body parsing requires express.json() middleware. Generate ids with a simple incrementing counter — no uuid library needed. Keep all state in the module-level array so tests can share the running server.

Model

sonnet

## Goal Refactor the hardcoded todos array in index.js into a mutable in-memory array, then add POST /todos (create) and DELETE /todos/:id (delete) endpoints. Base work on the agent/issue-3 branch. POST must accept a JSON body with a `title` field, assign a unique numeric id, set `done: false`, and return the created item with HTTP 201. DELETE must return 204 on success and 404 when the id does not exist. No database required. ## Done criteria - [ ] index.js declares a mutable `let todos = [...]` (or equivalent) instead of a hardcoded const - [ ] POST /todos with body `{"title":"buy milk"}` returns HTTP 201 and JSON containing `id`, `title`, and `done: false` - [ ] Two successive POST requests produce items with distinct numeric ids - [ ] DELETE /todos/:id for a valid id returns HTTP 204 and the item is absent from a subsequent GET /todos - [ ] DELETE /todos/:id for a non-existent id returns HTTP 404 - [ ] GET /healthz still returns HTTP 200 ## Hints Express body parsing requires `express.json()` middleware. Generate ids with a simple incrementing counter — no uuid library needed. Keep all state in the module-level array so tests can share the running server. ## Model sonnet
Author
Owner

agent dev-01: PR opened → #7

agent dev-01: PR opened → https://gitea.dannyhaslund.dk/danny8632/todo-app/pulls/7
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: danny8632/todo-app#5