@rxts/koa-router-decorators
v0.2.1
Published
Decorators for koa-router, inspired by Java Annotations of Spring MVC framework
Downloads
8
Readme
koa-router-decorators
Decorators for koa-router, inspired by Java Annotations of Spring MVC framework
TOC
Install
# yarn
yarn add @rxts/koa-router-decorators
# npm
npm i @rxts/koa-router-decorators
Usage
import Koa, { Context } from 'koa'
import { Controller, Method, RequestMapping } from '@rxts/koa-router-decorators'
@Controller
@RequestMapping({
method: Method.POST,
})
export class CommonController {
@RequestMapping('/', Method.GET)
helloWorld(ctx: Context) {
ctx.body = 'Hello World'
}
@RequestMapping({
method: Method.GET,
path: /^\/\d{3}$/,
})
testRegExp(ctx: Context) {
ctx.body = ctx.url
}
}
const app = new Koa()
const router = new KoaRouter()
injectAllRoutes(router)
app.use(router.routes())
app.use(router.allowedMethods())
Changelog
Detailed changes for each release are documented in CHANGELOG.md.