@seregpie/koa-route
v19.0.1
Published
A simple route middleware.
Downloads
4
Readme
KoaRoute
A simple route middleware.
dependencies
setup
npm i @seregpie/koa-route
usage
let Koa = require('koa');
let KoaRoute = require('@seregpie/koa-route');
let app = new Koa();
let items = [];
app.use(KoaRoute.post('/items', async ctx => {
let item = await KoaBody.json(ctx);
let itemIndex = items.length;
items.push(item);
ctx.body = itemIndex;
}));
app.use(KoaRoute.get('/items/:itemIndex', ctx => {
let {itemIndex} = ctx.params;
let item = items[itemIndex];
ctx.body = JSON.stringify(item);
}));