parameters-middleware
A middleware for express that checks if the required parameters are set in the request.
Note that this middleware only checks if the parameters are defined in the expected object. It DOES NOT validate the values.
Usage
npm install parameters-middleware
In your route definitions:
var express = ;var parameters = ; var app = ; // Commonly used requirements can be defined only once and re-used// throughout your code.var requireToken = ; app ;
Options
The parameters-middleware
allows you to pass an options object as its
second argument.
statusCode
By default, the parameters-middleware
sends a response with status code
400 Bad Request
if any parameter is missing, but you can change it with
the statusCode
option:
// Responds with `404 Not Found` if the `q` param is not defined in the// request's query.app;
message
By default, a default message will be set depending on the configured status
code sent by the response (Bad Request
for status code 400
, Not Found
for
status code 404
, and so on).
If you wish to change this, use the message
option.
app;
The message
option also accepts a function, which receives an array
containing the missing parameters and should return a message string.
{ return 'Missing params: ' + missing;} app;
License
This project is distributed under the MIT license. See the LICENSE
file for
more details.