Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joyqi/ts-koa-router-decorators
Koa router decorators for TypeScript
https://github.com/joyqi/ts-koa-router-decorators
Last synced: 17 days ago
JSON representation
Koa router decorators for TypeScript
- Host: GitHub
- URL: https://github.com/joyqi/ts-koa-router-decorators
- Owner: joyqi
- License: mit
- Created: 2021-11-12T07:31:26.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-14T10:11:09.000Z (almost 3 years ago)
- Last Synced: 2024-10-13T10:53:26.441Z (about 1 month ago)
- Language: TypeScript
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.