# ts-koa-router-decorators

> Koa router decorators for TypeScript

Latest version **1.0.6** (published 2022-01-14) · MIT license · 0 weekly downloads

## Install

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

## 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.6 |
| Published | 2022-01-14 |
| First published | 2021-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | joyqi |
| Maintainers | joyqi |

## Links

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

## Recent versions

- 1.0.6 (latest) — 2022-01-14
- 1.0.5 — 2021-11-13
- 1.0.4 — 2021-11-13
- 1.0.3 — 2021-11-12
- 1.0.2 — 2021-11-12
- 1.0.1 — 2021-11-12
- 1.0.0 — 2021-11-12

## README

# ts-koa-router-decorators
Koa router decorators for TypeScript

## Installation

```
npm i ts-koa-router-decorators
```

You need to install `koa` and `koa-router` before.

```
npm i koa koa-router
```

## Example

```typescript
import Koa, { Context } from 'koa';
import {controller, get, route} from 'ts-koa-router-decorators';

@controller()
class Test {
    @get('/')
    test(ctx: Context) {
        ctx.body = 'Hello world!';
    }
}

const app = new Koa();
route(app);

app.listen(8000, () => {
    console.log('http serving...');
});
```

## API

### Decorators

* `@controller(prefix: string)`, prefix default value is `''`
* Http methods
  * `@get(path: string, ...middlewares: IMiddleware[])` GET method
  * `@post(path: string, ...middlewares: IMiddleware[])` POST method
  * `@put(path: string, ...middlewares: IMiddleware[])` PUT method
  * `@del(path: string, ...middlewares: IMiddleware[])` DELETE method
  * `@patch(path: string, ...middlewares: IMiddleware[])` PATCH method
  * `@options(path: string, ...middlewares: IMiddleware[])` OPTIONS method
  * `@head(path: string, ...middlewares: IMiddleware[])` HEAD method
  * `@all(path: string, ...middlewares: IMiddleware[])` All methods
  * `@any(path: string, ...middlewares: IMiddleware[])` Alias to `all`

### Functions

```
route(app: Koa)
```

Perform router register, this action will create all insntaces of controllers automatically.

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