0.0.7 • Published 4 years ago

roa-restful v0.0.7

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

roa-restful

实现基于装饰器koa-router路由定义。 类似基于JAVA使用注解编程以及面向对象分析世界 。:smile:

安装

npm i --save roa-restful

使用

首先定义一个控制器类,对应着koa-routerRouter

const {
    Controller,
    Get,
    Post,
    Delete,
    Put
} =  require("roa-restful)

@Controller("/user")
export class UserController {

    @Get("/userInfo")
    async (ctx, next) => {
        // .....just like that
    }

}

你可以在项目的任何地方导入你的控制器类,当装饰器运行时,会往控制器类的prototype上添加一个Router实例属性。

const router: Router = UserController["router"];

取得router后,你便可以向往常一样使用koa-router的方式

app.use(router.routes());
// or
app.use(UserController["router"].routes());

Doucuments

@Controller

对应koa-routerRouter

参数

paramtypedescriptiondefault
prefixstringRouter的前缀/根路径""
configobject对应Routeropts{}

@Get、Post、Delete、Put

参数

paramtypedescriptiondefault
urlstring路径表达式"/"

后续更新

  • 实现koa-routerNamed routes

  • 实现koa-routerMultiple middleware

  • 添加Typescript的声明文件。

要求

  • 项目需是使用Koa
  • 使用koa-router
0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago