# koa-route

> Koa route middleware

Latest version **4.0.1** (published 2024-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-route
pnpm add koa-route
yarn add koa-route
bun add koa-route
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2024-02-25 |
| First published | 2013-11-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/koa-route) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 3.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 447 |
| Maintainers | coderhaoxin, aaron, juliangruber, eivifj, travisjeffery, dead_horse, tjholowaychuk, tejasmanohar, jongleberry, fengmk2 |
| Keywords | koa, middleware, routes, router, route |

## Links

- npm: https://www.npmjs.com/package/koa-route
- Repository: https://github.com/koajs/route
- Homepage: https://github.com/koajs/route#readme
- Issues: https://github.com/koajs/route/issues
- npm.io page: https://npm.io/package/koa-route

## Dependencies (3)

- [debug](https://npm.io/package/debug.md) *
- [methods](https://npm.io/package/methods.md) ~1.1.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.1

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 4.0.1 (latest) — 2024-02-25
- 3.2.0 (next) — 2016-08-24
- 4.0.0 — 2024-02-25
- 3.1.0 — 2016-03-18
- 3.0.0 — 2015-11-17
- 2.4.2 — 2015-07-02
- 2.4.1 — 2015-04-12
- 2.4.0 — 2014-11-28
- 2.3.0 — 2014-11-28
- 2.2.0 — 2014-10-15
- 2.1.0 — 2014-08-17
- 2.0.0 — 2014-08-07
- 1.1.4 — 2014-05-02
- 1.1.2 — 2014-04-18
- 1.1.1 — 2014-03-19
- … 4 more at https://npm.io/package/koa-route/versions

## README

# koa-route

 Uber simple route middleware for koa.

```js
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](https://github.com/koajs/router),
 a Koa clone of express-resource.

## Installation

```js
$ npm install koa-route
```

## Example

  Contrived resource-oriented example:

```js
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');
});
```

## License

  MIT

---
_Source: https://npm.io/package/koa-route · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
