Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including koa-route with all npm packages installed. Try it out:

var koaRoute = require("koa-route")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koa-route v3.2.0

Koa route middleware


Uber simple route middleware for koa.

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

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


$ npm install koa-route@next


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 = + ' is a ' + pet.species;

app.use(_.get('/pets', pets.list));

console.log('listening on port 3000');




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free