Files
What you'll learn
- Read a path parameter with c.req.param('id'), and all of them at once with c.req.param()
- Register routes for other verbs, and answer 204 with c.body(null, 204)
- Rely on registration order: Hono tries routes in the order they were added, so a fixed path goes before a parameter that would swallow it
Press Run tests to start the app. Its log appears here.Graded endpoints
The three cats the app starts with
A fixed path registered before /cats/:id, or :id would take it with id = "newest"
c.req.param('id') is the string "2"; the handler finds the cat with that number
No cat has id 99: a JSON error with status 404 from c.json(body, 404)
Two parameters read at once with c.req.param(); the field's value as plain text, not JSON
A field the cat does not have is a 404 with a message naming it
The DELETE route looks the cat up first and answers the same 404 as GET
A DELETE route; nothing to say back, so 204 and no body
Tom is gone: looking him up is the same 404 as any missing cat
The array lives as long as the app, so the removal is visible to the next request
A path no route claims is Hono's own 404 Not Found text, not one of yours