# koa2-route-decorator

> koa2-router-decorator

Latest version **1.0.5** (published 2018-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa2-route-decorator
pnpm add koa2-route-decorator
yarn add koa2-route-decorator
bun add koa2-route-decorator
```

## 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 | 1.0.5 |
| Published | 2018-09-10 |
| First published | 2018-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jingbo |
| Maintainers | jingbo925 |
| Keywords | koa, router, koa2, decorator |

## Links

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

## Dependencies (3)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [koa-router](https://npm.io/package/koa-router.md) ^7.4.0

## 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

- 1.0.5 (latest) — 2018-09-10
- 1.0.4 — 2018-09-10
- 1.0.3 — 2018-09-10
- 1.0.2 — 2018-09-10
- 1.0.1 — 2018-09-10
- 1.0.0 — 2018-09-07

## README

## install
```
npm i koa2-route-decorator
```

## Decorators

- @router(path)
- @get(path, middleware)
- @post(path, middleware)
- @put(path, middleware)
- @del(path, middleware)
- @use
- @all

## demo

```
index.js

import {Route} from 'koa2-route-decorator'
import Koa from 'koa'
import { resolve } from 'path'

const app = new Koa()
const apiPath = resolve(__dirname, '../routes')
const router = new Route(app, apiPath)
router.init()
```

```
import {router, get, post, put } from 'koa2-route-decorator'

@router('/user')
export class userController {
  @get('/' )
  async login(ctx, next) {

    const user = await User.findOne()


    const token = createToken(user.dataValues)
    ctx.body = {
      data: token
    }
  }

  @post('/sign', checkToken())
  async sign(ctx, next) {
    const user = ctx.user
    ctx.body = {
      data: user
    }
  }
}
```

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