Praxent Validate Route Package
This package is to assist in validating a NodEJS route for params and authentication. Specifically, this method is expected be invoked as the function argument for an app route in Express.
How to Use
const validateRoute = require('@praxent/praxent-validate-route')
const validate = validateRoute(gatewayToken)
app.post('/path/to/route', validate({
action: (req, res) => res.json({ requestedData: req.body.data }),
requireAuth: true,
requiredParams: ['data'],
type: 'body',
});
Parameters
- action
- Required
- Type: Function
- Receives: 'req' and 'res' from express router
- requireAuth
- Not required, defaults to false
- Type: Bool
- Validates
req.headers.token
against the instantiated gatewayToken
- requiredParams
- Not required, default to empty array
- Type: Array of strings
- Name of parameters which are required for the request
- type
- Required if requiredParams is not an empty array
- Type: string
- Available strings:
- Determines whether to validate required params against the
body
or query
object in express' router (body for posts, query for gets)