1.1.0 • Published 5 years ago
koa-schema-router v1.1.0
koa-schema-router
JSON schema based router for Koa. Includes request parsing, validation and response serialization.
Example
const createSchemaRouter = require("koa-schema-router");
const Koa = require("koa");
const api = createSchemaRouter();
api.define({
method: "POST",
url: "/test",
schema: {
request: {
consumes: ["application/json"],
body: {
type: "object",
properties: {
test: { type: "string" }
}
}
},
response: {
200: {
type: "object",
properties: {
hello: { type: "string" }
}
}
}
},
handler(ctx) {
ctx.body = { hello: "world" };
}
});
const app = new Koa();
app.use(api);
app.listen(8080);