validate-express-req-body
Overview
validate-express-req-body
is a set of middlewares designed for use with express.js that allows you to validate and sanitize incoming requests. It provides a flexible system to apply various validation rules and constraints to your express requests, ensuring that your data meets your criteria..
Support
This version of validate-express-req-body
requires node.js 16+ and is compatible with express.js 4.x. While it is optimized for use with express.js, it may also work with other libraries that have similar HTTP request object structures. The key properties supported are:
req.body
: Contains the body of the HTTP request. It can handle any value, but objects, arrays, and other JavaScript primitives are typically more effective.req.params
: An object mapping route parameter names to their values, parsed from the request path and matched with the route definition.req.query
: The query string part of the request URL, parsed as an object mapping query parameter names to their values.req.headers
: The headers sent along with the HTTP request.req.cookies
: For validate the cookies. To validate the cookies you should use thecookie-parser
.
validate-express-req-body
supports validating these properties with various data types, as well as applying minimum and maximum constraints. It uses custom validation logic and does not rely on third-party packages.
Installation
validate-express-req-body
is on the npm registry! You can install it using your favorite Node.js package manager:
- npm
- Yarn
- pnpm
npm install validate-express-req-body
yarn add validate-express-req-body
pnpm add validate-express-req-body