docs: added controller class example (#20)
Validate plugin for egg.
See parameter for more information such as custom rule.
$ npm i egg-validate --save
// config/plugin.js exports.validate = { enable: true, package: 'egg-validate', };
egg-validate support all parameter’s configurations, check parameter documents to get more infomations.
// config/config.default.js exports.validate = { // convert: false, // validateRoot: false, };
// app/controller/home.js const Controller = require('egg').Controller; class HomeController extends Controller { async index() { const { ctx, app } = this; ctx.validate({ id: 'id' }); // will throw if invalid // or const errors = app.validator.validate({ id: 'id' }, ctx.request.body); } } module.exports = HomeController;
app.validator.addRule('jsonString', (rule, value) => { try { JSON.parse(value); } catch (err) { return 'must be json string'; } });
Please open an issue here.
MIT
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
egg-validate
Validate plugin for egg.
See parameter for more information such as custom rule.
Install
Usage
Configurations
egg-validate support all parameter’s configurations, check parameter documents to get more infomations.
Validate Request Body
Extend Rules
Questions & Suggestions
Please open an issue here.
License
MIT