API validation utilities.
You should be familiar with the valdsl validation library.
Methods
(static) validateRequestBody(req, optionsopt, callbacks) → {Promise.<ValidationContext>}
- Source:
Asynchronously validates the body of the specified request with any number of validators. This function returns a promise which is resolved if validation is successful. It is rejected if validation fails.
function validateAuthentication(req) {
return validate.requestBody(req, function() {
return this.parallel(
this.validate(
this.json('/email'),
this.required(),
this.type('string'),
this.email()
),
this.validate(
this.json('/password'),
this.required(),
this.type('string'),
this.notBlank()
)
);
})
}
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
req |
Request | The Express request object to validate. |
||||||||||||||||
options |
object |
<optional> |
Validation options (may be omitted). Properties
|
|||||||||||||||
callbacks |
Array.<function()> | Validation callbacks. |
Returns:
A promise that will be resolved with an empty valdsl ValidationContext if validation was successful, or rejected with a valdsl ValidationErrorBundle containing the list of errors if validation failed.
- Type
- Promise.<ValidationContext>
(static) validateValue(value, status, callbacks) → {Promise.<ValidationContext>}
- Source:
Asynchronously validates an arbitrary value with any number of validators. This function returns a promise which is resolved if validation is successful. It is rejected if validation fails.
Parameters:
Name | Type | Description |
---|---|---|
value |
* | The value to validate. |
status |
number | The HTTP status code that the response should have if validation fails. |
callbacks |
Array.<function()> | Validation callbacks. |
Returns:
A promise that will be resolved with an empty valdsl ValidationContext if validation was successful, or rejected with a valdsl ValidationErrorBundle containing the list of errors if validation failed.
- Type
- Promise.<ValidationContext>