1.1.20-koa • Published 4 years ago

koa-router-util v1.1.20-koa

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

NPM version Build Status

🥚 egg router decorator util -> simple way to define api router and generate apidoc

!! 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