0.3.8 • Published 6 years ago
koa2-router-decorator v0.3.8
koa2-router-decorator
koa-router decorator
Installation
$ npm i koa2-router-decorator --save
Usage
To use it with typescripts you should enable experimentalDecorators
and emitDecoratorMetadata
in tsconfig.json
Development
npm install -g typescript
npm install -g tslint
npm install koa --save
npm install @types/koa --save-dev
npm install reflect-metadata --save-dev
hello koa2-router-decorator
import "reflect-metadata"; // this shim is required
import { getApp } from "koa2-router-decorator"
const app = getApp(`${__dirname}/controller`);
app.listen(3000);
Example
import { Controller, Get, Post } from "koa2-router-decorator"
import { Context } from "koa";
@Controller("/user")
export class User {
@Get("/seay")
async seay(ctx: Context) {
return { err_code: 0, msg: "hello world!" }
};
@Post("/")
async create(ctx: Context) {
const { name, age, sex } = ctx.request.body;
ctx.status = 200;
ctx.body = {
err_code: 0,
data: {
name,
age,
sex
}
}
}
}
0.3.8
6 years ago
0.3.7
6 years ago
0.3.6
6 years ago
0.3.5
6 years ago
0.3.4
6 years ago
0.3.3
6 years ago
0.3.2
6 years ago
0.3.1
6 years ago
0.2.9
6 years ago
0.2.8
6 years ago
0.2.7
6 years ago
0.2.6
6 years ago
0.2.5
6 years ago
0.2.4
6 years ago
0.2.3
6 years ago
0.2.2
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.9
6 years ago
0.1.8
6 years ago
0.1.7
6 years ago
0.1.6
6 years ago
0.1.5
6 years ago
0.1.4
6 years ago
0.1.3
6 years ago
0.1.2
6 years ago
0.1.1
6 years ago
0.1.0
6 years ago