
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
koa-route
Advanced tools
Uber simple route middleware for koa.
const _ = 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.
$ npm install koa-route
Contrived resource-oriented example:
const _ = require('koa-route');
const Koa = require('koa');
const app = new Koa();
const db = {
tobi: { name: 'tobi', species: 'ferret' },
loki: { name: 'loki', species: 'ferret' },
jane: { name: 'jane', species: 'ferret' }
};
const pets = {
list: (ctx) => {
const names = Object.keys(db);
ctx.body = 'pets: ' + names.join(', ');
},
show: (ctx, name) => {
const 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, (err) => {
if (err) console.error(err.stack);
else console.log('listening on port 3000');
});
MIT
FAQs
Koa route middleware
The npm package koa-route receives a total of 117,144 weekly downloads. As such, koa-route popularity was classified as popular.
We found that koa-route demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.