egg-router-util
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

NPM version Build Status

🥚 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 

Package Sidebar

Install

npm i egg-router-util

Weekly Downloads

2

Version

2.0.1

License

MIT

Unpacked Size

44.4 kB

Total Files

26

Last publish

Collaborators

  • zhuziyu