koa-router的基本用法

    1. const Koa = require('koa');
    2. const KoaRouter = require('koa-router');
    3. const app = new Koa();
    4. const router = new KoaRouter();
    5. router.get('/', (ctx, next) => {
    6. ctx.body = {key: 'index'}
    7. });
    8. router.post('/users', (ctx, next) => {
    9. ctx.body = {key: 'post'}
    10. });
    11. router.put('/users', (ctx, next) => {
    12. ctx.body = {key: 'put'}
    13. });
    14. router.delete('/user', (ctx, next) => {
    15. ctx.body = {key: 'delete'}
    16. });