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

Refactoring routes

We previously created the teams-api.js file in the routes folder. Open that file and apply the following changes:

const express = require('express')const api = new express.Router()let teams = [    { id: 1, name: "Peru"},    { id: 2, name: "Russia"}]

First, we import the express module. From this module, we are declaring the api variable, which is an instance of express.Router. A teams variable has been created in order to host some fake data for the teams. We will use this router to configure our CRUD/HTTP handlers, as follows:

api  .route('/teams')  .get((req, res) => {    res.json(teams)  })  .post((req, res) => {      })app.listen(3000, () => {...

Using the api route variable, we define the '/teams' path as root for the HTTP handlers. ...

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