Consider the following Express code:
router.get('/v1/api/book/:id', function (req, res) {
if (!req.params.id)
res.status(401).send('Missing book id');
res.status(200).send('Book found!');
});
- By invoking
http://myserver/v1/api/book/12345689
, the application returns 200 >Book found!
, as expected. - However,
http://myserver/v1/api/book
returns 404 >Cannot GET /v1/api/book
, instead of 401 >Missing book id
.
Could you please explain me why and how could I fix this behaviour?