easyStudy question · answer published in REST API interview questions, so no pointsapi-designexpressvalidation
Route parameter never matches a number
In Express, a route /orders/:id runs this check. For a request to /orders/42 it always says not found. Why?
app.get('/orders/:id', (req, res) => {
const order = orders.find(o => o.id === req.params.id)
if (!order) return res.sendStatus(404)
res.json(order)
})
// orders = [{ id: 42, ... }]Discussion 0
Join free to post in the discussion.
Related questions
- Response for a successful DELETEBackend Developer
- A product page removed for goodBackend Developer
- Signing up with a taken usernameBackend Developer
- Calling DELETE on a read-only routeBackend Developer
- A client posts XML to a JSON APIBackend Developer
- URL for one productBackend Developer
- Telling the client where the new item livesBackend Developer
- Filtering and sorting a listBackend Developer