1.1.0 • Published 5 years ago

koa-schema-router v1.1.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
5 years ago

koa-schema-router

build status test coverage npm version minified size MIT licensed

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);
1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago