Build REST endpoints: 12 levels of GET, POST, PUT and DELETE, params, body and headers. A Node.js API game for beginner backend developers.
Express calls a route's handler when a request's method and path match it. The handler gets req (what was asked) and res (the reply), and must send a reply, for example with res.json(...). A request that matches no route is refused by Express itself with 404.
A route with :name in its path catches that part of the request's address. app.get('/api/kursi/:no', ...) catches 7 from /api/kursi/7 as req.params.no, and its value is always text ('7'), not a number.
A POST slip's body comes as a stream of bytes. The express.json() middleware reads it and puts the result in req.body; without that middleware there is no req.body. For something newly made, HTTP uses status 201 Created and a Location header pointing at the new thing.
res.status(code) only chooses the reply's status and returns res, so that you can chain on it. The reply is sent when res.json(...), res.send(...) or res.end() is called; res.status(...) alone leaves the buyer waiting.