Wondering what‚Äôs next for npm?Check out our public roadmap! ¬Ľ

    koa-route
    DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/koa-route package

    3.2.0¬†‚Äʬ†Public¬†‚Äʬ†Published

    koa-route

    Uber simple route middleware for koa.

    var _ = require('koa-route');
    app.use(_.get('/pets', pets.list));
    app.use(_.get('/pets/:name', pets.show));

    If you need a full-featured solution check out koa-router, a Koa clone of express-resource.

    Installation

    $ npm install koa-route@next

    Example

    Contrived resource-oriented example:

    var _ = require('koa-route');
    var Koa = require('koa');
    var app = new Koa();
     
    var db = {
      tobi: { name: 'tobi', species: 'ferret' },
      loki: { name: 'loki', species: 'ferret' },
      jane: { name: 'jane', species: 'ferret' }
    };
     
    var pets = {
      list: (ctx) => {
        var names = Object.keys(db);
        ctx.body = 'pets: ' + names.join(', ');
      },
     
      show: (ctx, name) => {
        var pet = db[name];
        if (!pet) return ctx.throw('cannot find that pet', 404);
        ctx.body = pet.name + ' is a ' + pet.species;
      }
    };
     
    app.use(_.get('/pets', pets.list));
    app.use(_.get('/pets/:name', pets.show));
     
    app.listen(3000);
    console.log('listening on port 3000');

    License

    MIT

    Install

    npm i koa-route

    DownloadsWeekly Downloads

    67,508

    Version

    3.2.0

    License

    MIT

    Last publish

    Collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar
    • avatar