@thedevminertv/body-validator

1.2.0 • Public • Published

BodyValidator

BodyValidator allows you to easily check if the request body has certain properties.

Installation

npm install @thedevminertv/body-validator

Usage

const app = require('express')();
const BodyParser = require('body-parser');

const BodyValidator = require('@thedevminertv/body-validator');

// Apply BodyParser to parse JSON
app.use(BodyParser.json());

// Apply the BodyValidator to a route
// This will check that the body should have the "name" property
app.get('/api/test', BodyValidator(['name']), (request, response) => {
	res.send(`Hello ${req.body.name}`);
});

app.listen(3000, () => console.log('Server listening on port 3000'));

/@thedevminertv/body-validator/

    Package Sidebar

    Install

    npm i @thedevminertv/body-validator

    Weekly Downloads

    1

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    4.18 kB

    Total Files

    5

    Last publish

    Collaborators

    • thedevminertv