Files
What you'll learn
- Read the query string with c.req.query() and a header with c.req.header()
- Parse a JSON body with await c.req.json<T>() in an async handler
- Set a status with the second argument of c.json() and a response header with c.header()
Press Run tests to start the app. Its log appears here.Graded endpoints
The list, and an x-total-count header set with c.header() before the response is built
The JSON body is read with await c.req.json(); the answer is 201 with the stored cat and a Location header pointing at it
The new cat is in the array, and the count header follows
c.req.query('minAge') is the string "3"; only cats at least that old are answered, and the count header counts them
Without an Accept header asking for text, the cat is JSON
c.req.header('accept') says text/plain, so the handler answers the name with c.text()
The body's fields are merged into the cat and the updated cat is answered
The change was made on the stored cat, not on a copy
The lookup's 404, unchanged from the last lesson
The lookup fails before the body matters: the same 404 as reading it