egg-router-util
v2.0.1
Published
egg router decorator util -> simple way to define api router
Downloads
5
Readme
🥚 egg router decorator util -> simple way to define api router
!! Warning: this package only support typescript.
Install
npm i egg-router-util
Usage
在router
入口中接管路由处理函数
// app/router.ts
import { Application } from 'egg';
import { RouterHandle } from 'egg-router-util';
export default (app: Application) => {
RouterHandle(app);
};
在controller
中使用注解(decorator)
// app/controller
import { Controller } from 'egg';
import { All, Body, Get, Params, Prefix, Query, Use } from 'egg-router-util';
@Prefix('/api')
export default class HomeController extends Controller {
@Use([ 'hello' ])
@All('/:id')
async index(@Body('title')body, @Query('code')query, @Params('id')params) {
this.ctx.logger.debug(body, query, params);
this.ctx.body = 'Hello World!';
}
@Get('/test/:id')
async test(ctx) {
this.ctx.logger.info(ctx);
this.ctx.body = 'YES';
}
}
// done