hapijs-ajv
A very simple combination of hapi and ajv.
Usage
This plugin helps you check two inputs: query string and simple payload.
- Register the plugin into hapi:
server;
- For each route, if you want the plugin to do a JSON schema check, then you need to add
hapijs-ajv
config toplugins
. The config has two optional keys,payloadSchema
andquerySchema
, which are schemas for each input. Values for those two keys are Ajv JSON schema object.
If any of the schema cannot pass, error 400 is thrown. By default, key ajvError
in the response will contains the mismach information, provided by Ajv. If you want to have your own way to handle the info, remember to pass processError
in plugin options.
Example:
api;