@praxent/praxent-validate-route

1.0.4 • Public • Published

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:
      • body
      • query
    • Determines whether to validate required params against the body or query object in express' router (body for posts, query for gets)

Package Sidebar

Install

npm i @praxent/praxent-validate-route

Weekly Downloads

3

Version

1.0.4

License

ISC

Unpacked Size

7.24 kB

Total Files

14

Last publish

Collaborators

  • nadeemkhedr
  • jbodkin
  • praxent-engineering