0.2.1 • Published 4 years ago

@rxts/koa-router-decorators v0.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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.

License

MIT © JounQin@1stG.me