O'Reilly logo

Hands-On Full Stack Web Development with Aurelia by Erikson Haziz Murrugarra Sifuentes, Diego Jose Arguelles Rojas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding a single team

To find a single team, we will make use of the findById built-in method, and we will pass a valid ID to it. So, apply the following changes:

api  .route('/teams/:id')  .get((req, res, next) => {      let id = req.params.id      Team.findById(id)        .then(data => res.json(data))        .catch(err => next(err))  })  .put((req, res) => {    // TODO  })  .delete((req, res) => {    // TODO  })

First, we extract the ID from the req.params object. Note that we are not using the /teams route. Instead, we are using the /teams/:id route. It means that Express.js will inject the id attribute as an element of the params object. Then, we call the findById method and send the response to the client. Let's test it:

$ curl http://localhost:3000/teams/5a662fbf728726072c6298fc ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required