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 the REST controller

Let's start by creating a new file in the src/routes folder named admin-api.js. Then, write the following code:

const express = require('express')const api = express.Router()api  .route('/admin/match/:id?')  .post((req, res, next) => {          // logic to create Match       })   .put((req, res, next) => {     
     // logic to update Scores       })module.exports = api

You are very familiar with this code structure. First, we import the modules required to define our REST controller. Secondly, we create a /admin/match/:id? route and define the POST method to create a new match and another PUT method to update the scores.

Pay attention to the route definition; we are declaring an optional path variable called :id. To make a path optional, ...

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