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

Creating a team

To create a team, we need to implement the POST handler. The data to the new team will be sent into the body parameter into the HTTP Request. Apply the following changes to the teams-api.js file:

...api  .route('/teams')  ...  .post((req, res) => {    let team = req.body    teams.push(team)    res.status(201).json(team)  })  ......

First, we read the data from the req.body property. Then, we insert the new element into the teams array. Lastly, we send the teams array with the new team added and specify the HTTP status 201, which means Resource Created.

You can find the full list of HTTP statuses at https://en.wikipedia.org/wiki/List_of_HTTP_status_codes.

To test things out, we will call our API using the following command:

$ curl -X POST ...

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