Feathers hooks validator
This repo modules for the feathersjs framework
Quick start
feathers-hooks-validator
allows to register hooks in before when a hook's executes validator. This makes it easy to check rule data processing and error handling from your service logic.
To install from npm, run:
$ npm i feathers-hooks-validator --save
Then, to use the plugin in your Feathers app:
const feathers = ;const hooks = ;const validator = ; const app = ;app;// Set up after set up hooksapp;
Then, you can register a hook for a service:
// User serviceconst service = ; module{ const app = this; let { return } // Initialize our service app; // Get our initialize service to that we can bind hooks const userService = app; // Set up our before hook userService;}
Documentation
Use package indicative
validator data
Structure validator
methods: 'create''update' useQuery: true rules: username: 'required|max:20' password: 'required|max:20' messages: required: '{{field}} is required to complete registeration process' ...
methods
: the methods using with check ruleuseQuery
: uses data on query inurl
when check rulerules
: rule was defined in packageindicative
messages
: custom message instead of a self-constructed message in packageindicative
Message Error Response
{
"name": "BadRequest",
"message": "Invalid data",
"code": 400,
"className": "bad-request",
"data": {},
"errors": [
{
"field": "password",
"validation": "required",
"message": "required validation failed on message"
}
]
}