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

List Matches

To list our matches, we won't need security, because all the users should be able to get the full list of matches in the applications. So let's implement the matches API.

So, create a new file called matches-api.js into the src/routes folder and apply the following code:

const express = require('express')const api = express.Router()const Match = require('../models/match')api  .route('/matches')  .get((req, res, next) => {     Match.find().exec()        .then(matches => res.json(matches))        .catch(err => next(err))  })module.exports = api

Next, we have to configure the server.js file to map our Match APIs. In the server.js file, apply the following change:

...const adminApi = require('./src/routes/admin-api')const matchesApi = require('./src/routes/matches-api') ...

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