express-requires
An express middleware for validating request fields and query parameters and returns a nicely formatted informative response. Performs two simple use cases:
- Prevent unexpected parameters from being accepted
- Requiring parameters to be passed to continue
- Or both chained together
Setup
npm install express-requires --save
Can be used on your whole app or just a single router
var requires = app;// or var router = express;router; //How to userouter
A bad request would return error code400
Can change the order to make a certain error condition take precedence.
reqreqreqreq
Validating Lists
The above validations can also be done on a list object.
router
Example Request
Response
Example 2
Response
Extra Options
Can optionally add the code and success flag to the response body in event of an error.
app;
Returns
Run Tests
The tests use a mock express server with the middleware in place and a series of mocha chai tests
npm test
npm cover