# koa2-router-decorator

> ES7 decorators for koa-router model

Latest version **0.3.8** (published 2018-10-05) · ISC license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.8 |
| Published | 2018-10-05 |
| First published | 2018-09-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 19.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | spadesk |
| Maintainers | spadesk |
| Keywords | koa2-router, decorator, koa, RESTful, API, router |

## Links

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

## Dependencies (6)

- [koa](https://npm.io/package/koa.md) ^2.5.3
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [@types/koa](https://npm.io/package/@types/koa.md) ^2.0.46
- [koa-router](https://npm.io/package/koa-router.md) ^7.4.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.116
- [@types/koa-router](https://npm.io/package/@types/koa-router.md) ^7.0.32

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

- 0.3.8 (latest) — 2018-10-05
- 0.3.7 — 2018-10-05
- 0.3.6 — 2018-10-05
- 0.3.5 — 2018-10-05
- 0.3.4 — 2018-10-05
- 0.3.3 — 2018-10-05
- 0.3.2 — 2018-09-25
- 0.3.1 — 2018-09-25
- 0.2.9 — 2018-09-25
- 0.2.8 — 2018-09-25
- 0.2.7 — 2018-09-25
- 0.2.6 — 2018-09-25
- 0.2.5 — 2018-09-25
- 0.2.4 — 2018-09-25
- 0.2.3 — 2018-09-25
- … 13 more at https://npm.io/package/koa2-router-decorator/versions

## README

# koa2-router-decorator
koa-router decorator 


## Installation

```bash
$ npm i koa2-router-decorator --save
```

## Usage

To use it with typescripts you should enable `experimentalDecorators` and `emitDecoratorMetadata` in `tsconfig.json`


### Development 

```bash
npm install -g typescript
npm install -g tslint
npm install koa --save
npm install @types/koa --save-dev
npm install reflect-metadata --save-dev
```


# hello koa2-router-decorator

```js
import "reflect-metadata"; // this shim is required

import { getApp } from "koa2-router-decorator"

const app = getApp(`${__dirname}/controller`);
app.listen(3000);
```


### Example

```js
import { Controller, Get, Post } from "koa2-router-decorator"
import { Context } from "koa";
@Controller("/user")
export class User {
    @Get("/seay")
    async seay(ctx: Context) {

        return { err_code: 0, msg: "hello world!" }
    };
    @Post("/")
    async create(ctx: Context) {
        const { name, age, sex } = ctx.request.body;

        ctx.status = 200;
        ctx.body = {
            err_code: 0,
            data: {
                name,
                age,
                sex
            }
        }
    }
}

```

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