Joi Specs

xpress-req-validator relies on Joi to do all validation tasks. You can validate following sources of a request (all are optional)

  • header

  • path

  • query

  • body

You must define Joi specs separately and assign them to each corresponding source.

example
'/user/:id': {
    header: USER_HEADER_SPEC,
    path: USER_PATH_SPEC,
    query: USER_QUERY_SPEC,
    body: USER_BODY_SPEC,
}

xpress-req-validator validates only the specified sources of request. Any undefined source will not be validated by the middleware

Last updated

Was this helpful?