1.3.2 • Published 5 years ago

hapi-joi-express v1.3.2

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

Express middleware for handling Joi validations with typescript support.

Middleware that helps with the property validation, if the test passes, next function in the row will be invoked, otherwise, the server responds with 422 status and JSON object with a list of errors.

API

const app = require("express")();
const { bodyValidation } = require("hapi-joi-express");
// also available: { paramsValidation, queryValidation }

const schema = Joi.object({ username: Joi.string().required() });

app.post("/login", bodyValidation(schema), (req, res) => res.json({ hello: "world" }));

ES6 imports

import express from "express";
import { queryValidation } from "hapi-joi-express";
// also available: { paramsValidation, queryValidation }

const app = express();

const schema = Joi.object({ username: Joi.string().required() });

app.post("/login", bodyValidation(schema), (req, res) => res.json({ hello: "world" }));