# koa-router-ts

> ## install

Latest version **3.0.0** (published 2019-05-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-router-ts
pnpm add koa-router-ts
yarn add koa-router-ts
bun add koa-router-ts
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-05-22 |
| First published | 2018-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | gongzili456 gongzili456@gmail.com |
| Maintainers | liuguili |

## Links

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

## Dependencies (6)

- [koa](https://npm.io/package/koa.md) ^2.5.2
- [@types/koa](https://npm.io/package/@types/koa.md) ^2.0.46
- [koa-router](https://npm.io/package/koa-router.md) ^7.4.0
- [require-dir](https://npm.io/package/require-dir.md) ^1.0.0
- [@types/koa-router](https://npm.io/package/@types/koa-router.md) ^7.0.31
- [@types/require-dir](https://npm.io/package/@types/require-dir.md) ^1.0.0

## Recent versions

- 3.0.0 (latest) — 2019-05-22
- 2.0.0 — 2019-03-14
- 1.0.2 — 2019-03-13
- 1.0.1 — 2019-03-13
- 1.0.0 — 2018-08-24

## README

# Useage

## install

`npm install koa-router-ts`

`yarn add koa-router-ts`

## Usage

### 1. Load all controller

```
import { loadControllers } from 'koa-router-ts'
import Koa from 'koa'

const app = new Koa()

const router = loadControllers('./controllers', { recurse: true })

app.use(router.routes())
app.use(router.allowedMethods())
```

### 2. decorate controller

#### Usage 2.x version

```
import { Controller, Get } from 'koa-router-ts'

@Controller('/admin')
export default class {

  @Get('/hello-admin', passport.authenticate('jwt'))
  async hi(ctx: any) {
    ctx.body = 'hi, i am admin.'
  }

}
```

#### Usage 1.x version

```
import { controller, route, HttpMethod } from 'koa-router-ts'

@controller('/users')
export default class UserController {

    @router('/:id', HttpMethod.GET, passport.authenticate('jwt'))
    async userInfo(ctx: any) {}

}
```

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