Files
main.tsmain
What you'll learn
- Mount express.json() so JSON request bodies arrive in req.body, and handle a body that was not parsed
- Declare several methods on one path with app.route()
- Answer a create with res.status(201).location(…).json(…) and a delete with res.sendStatus(204)
Press Run tests to start the app. Its log appears here.Graded endpoints
express.json() put the body in req.body; 201, the stored cat, and a Location
Milo is stored
A body without both fields is the client's mistake: 400
express.json() only reads JSON, so req.body stays undefined: still a 400, not a crash
GET on the route declared with app.route()
The body's fields are applied to the stored cat
The change was made to the stored cat
404 from the PATCH handler
res.sendStatus(204): the status, and no body
404 from the DELETE handler
404 from the GET handler
The collection works as before after a delete: the new cat is stored and answered