# @zcorky/koa-router

> simple router for koa

Latest version **0.0.4** (published 2018-12-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zcorky/koa-router
pnpm add @zcorky/koa-router
yarn add @zcorky/koa-router
bun add @zcorky/koa-router
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2018-12-06 |
| First published | 2018-12-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Zero |
| Maintainers | uniquecolesmith |

## Links

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

## Dependencies (2)

- [koa-compose](https://npm.io/package/koa-compose.md) ^4.1.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^2.4.0

## Recent versions

- 0.0.4 (latest) — 2018-12-06
- 0.0.3 — 2018-12-06
- 0.0.2 — 2018-12-03
- 0.0.1 — 2018-12-03

## README

# koa-router

[![NPM version](https://img.shields.io/npm/v/@zcorky/koa-router.svg?style=flat)](https://www.npmjs.com/package/@zcorky/koa-router)
[![Coverage Status](https://img.shields.io/coveralls/zcorky/koa-router.svg?style=flat)](https://coveralls.io/r/zcorky/koa-router)
[![Dependencies](https://david-dm.org/@zcorky/koa-router/status.svg)](https://david-dm.org/@zcorky/koa-router)
[![Build Status](https://travis-ci.com/zcorky/koa-router.svg?branch=master)](https://travis-ci.com/zcorky/koa-router)
![license](https://img.shields.io/github/license/zcorky/koa-router.svg)
[![issues](https://img.shields.io/github/issues/zcorky/koa-router.svg)](https://github.com/zcorky/koa-router/issues)

> Simple Router for Koa

### Install

```
$ npm install @zcorky/koa-router
```

### Usage

```javascript
// See more in test
import * as router from '@zcorky/koa-router';

import * as Koa from 'koa';
const app = new Koa();

app.use(router.get('/', async (ctx) => {
  ctx.body = 'home';
}));

app.use(router.get('/health', async (ctx) => {
  ctx.status = 200;
  ctx.body = 'ok';
}));

app.use(router.get('/product/:pid', async (ctx) => {
  ctx.body = ctx.params.pid;
}));

// support middlewares for router
const md5 = crypto.createHash('md5').update('123').digest('hex');

const responseTime = async (ctx, next) => {
  const start = Date.now();
  await next();
  ctx.set('X-Response-Time', Date.now() - start);
};

const requestId = async (ctx, next) => {
  await next();
  const id = md5(ctx.url + Date.now());
  ctx.set('X-Request-Id', id);
};

const handler = async (ctx) => {
  ctx.body = ctx.params.pid + ': ' + ctx.params.cid;
};

app.use(router.get('/product/:pid/:cid', responseTime, requestId, handler));

// fallback
app.use(async (ctx) => {
  ctx.body = {
    name: 'name',
    value: 'value',
  };
});

app.listen(8000, '0.0.0.0', () => {
  console.log('koa server start at port: 8000');
});
```

### Related
* [koa-router](https://github.com/alexmingoia/koa-router)
* [koa-route](https://github.com/koajs/route)
* [koa-compose](https://github.com/koajs/compose)

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