request-expect
Easily sanitize Koa and Express request bodies, throwing errors when required parameters are missing or invalid. Helps make your APIs self documenting.
Installation
Install package with NPM and add it to your development dependencies:
npm install --save-dev request-expect
Usage
Example for Koa
const koa = bodyParser = requestExpect = app = ; app;app;app; app;
Example for Express
const express = requestExpect = app = ; app;app; app;
Types
any
any typestring
same asany
but casts to a stringinteger
trims and runs parseIntnumber
same asinteger
, but runs parseFloat instead of parseInt if a decimal is present
All types are required by default. To make it optional, chain isOptional
. See the above examples.