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, we add the ? operator after its name.

So far so good. Let's implement them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset