June 2018
Intermediate to advanced
348 pages
8h 19m
English
We already have the list handler, but the listing is not enough. Apart from retrieving the full list, we will need to retrieve a single team. To do this, we will need to add a new GET route and learn how to use params. Apply the following changes into the teams-api.js:
...api .route('/teams')...api .route('/teams/:id') .get((req, res) => { const id = req.params.id for(let team of teams) { if (team.id == id) return res.json(team) } return res.status(404).send('team not found') })module.exports = api
First, we declare a new route, which now contains a dynamic param—/teams/:api. We said dynamic because, of course, it can take any value that will be available as an attribute of the req.params object. Note that the name you ...
Read now
Unlock full access