egg-async-validator
March 6, 2017 ยท View on GitHub
Async validate plugin for egg.
See async-validator for more information such as custom rule.
Install
$ npm i egg-async-validator --save
Enable plugin
// config/plugin.js
exports.validate = {
enable: true,
package: 'egg-async-validator',
};
Validate rules
All validate rules store on app/xxxx
Validate Request Body
// app/controller/home.js
exports.index = async () => {
await this.validate({ id: 'id' }); // will throw if invalid
// or
const errors = await this.validator.validate({ id: 'id' }, this.request.body);
};
Extend Rules
TBD
Questions & Suggestions
Please open an issue here.