1.0.2 • Published 4 years ago

koa-io-validator v1.0.2

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

koa-io-validator

npm node Build Status codecov Maintainability David deps Known Vulnerabilities npm bundle size NPM

Koa input/output validation middleware

Usage

import Koa from "koa";
import Router from "@koa/router";
import validate from ('koa-validator');

import Joi from "@hapi/joi"; // Required

const app = new Koa();
const router = new Router()

router.get(
    "/hello/:id",
    validate({
      query: {
        q: Joi.string().required()
      },
      params: {
        id: Joi.string().required()
      },
      headers: {
        "Content-Type": Joi.string()
          .valid("application/json", "application/javascript")
          .required()
      },
      200: {
        succuss: Joi.bool()
      }
    }),
    async (ctx, next) => {
      ctx.body = {
        succuss: true
      };
      await next();
    }
  );

app.use(router.routes());
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago