2.0.1 • Published 2 years ago

egg-router-util v2.0.1

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

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 
2.0.1

2 years ago

2.0.0

2 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.13

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago