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

Deleting a Team

The delete process is similar to the update. First, we need to retrieve a valid index from the teams array and then remove it from there. Open the teams-api.js file and apply the following changes:

...api  .route('/teams/:id')  .get((req, res) => {     ...  })  .put((req, res) => {     ...  })  .delete((req, res) => {    const id = req.params.id    const index = lookupTeam(id)    const team = teams[index]    if (index !== -1) {      teams.splice(index, 1)      return res.send(team)    }    return res.status(404).send('team not found')  })...

So we define a .delete route and look up for a team by passing the id param. If a valid index is returned, we save the team instance in the team variable. Next, we delete the element from the array using the splice(index, 1) expression. ...

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