@zhuziyu/egg-router
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

NPM version Build Status

egg router decorator -> 使用注解(decorator)定义API,简化路由配置。

!! 注意: 本插件只支持typescript版本的egg项目,js版本的暂未测试

安装

npm i @zhuziyu/egg-router

使用方法

router入口中注入

// app/router.ts
import { Application } from 'egg';
import { RouterHandle } from '@zhuziyu/egg-router';

export default (app: Application) => {
  RouterHandle(app);
};

controller中使用注解(decorator)

// app/controller
import { Controller } from 'egg';
import { All, Body, Get, Params, Prefix, Query, Use } from '../../../';

@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';
  }

}


// 完成,访问 `http://host:port/api/:id` 即可

Readme

Keywords

Package Sidebar

Install

npm i @zhuziyu/egg-router

Weekly Downloads

0

Version

1.1.4

License

MIT

Unpacked Size

36.7 kB

Total Files

32

Last publish

Collaborators

  • zhuziyu