Files
main.tsmain
What you'll learn
- Answer in the representation the client prefers with res.format(), including a default for none
- Check a request body's type with req.is(), and read and set cookies with cookie-parser, res.cookie() and res.clearCookie()
- Redirect with res.redirect(), choosing between a temporary and a permanent move
Press Run tests to start the app. Its log appears here.Graded endpoints
res.format() picked the JSON handler, and said so to caches with Vary
The same list in the representation the client asked for
The default handler's own 406, instead of Express's HTML page
req.is('application/json') is false: 415
JSON, but not a sort the API knows
Remembered in a cookie the page's scripts cannot read, answered with nothing to say
The cookie came back with the request, and cookie-parser put it in req.cookies
Both representations read the same preference
The cookie is replaced
Luna, Milo, Tom
res.clearCookie() sends the cookie back already expired, so the client drops it
No cookie, no sort
302 Found: a temporary redirect, since which cat is oldest can change
Luna
404, unchanged