November 2018
Beginner
132 pages
2h 57m
English
In order to be able to visit different endpoints, we need to set up some form of a router, to route different URL oath visits to different actions. Koa does not come bundled with an out-of-the-box router like Express does; hence, we will be making use of koa-router, which is an open source RESTful router for use with Koa.
Let's start off by creating a router.js file in the middleware folder, and inserting the following contents:
// ./middleware/router.jsconst KoaRouter = require('koa-router');const router = new KoaRouter();router .get('/', async ctx => (ctx.body = 'Welcome to the contacts API!'));module.exports = router;
In the preceding code block, we require the koa-router dependency, and we initialize it. After that, ...
Read now
Unlock full access