eggjs / Egg Validate
Licence: mit
validate plugin for egg
Stars: ✭ 224
Programming Languages
javascript
184084 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Egg Validate
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (-16.07%)
Mutual labels: egg, egg-plugin
Egg Security
Security plugin for egg, force performance too.
Stars: ✭ 204 (-8.93%)
Mutual labels: egg, egg-plugin
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-77.68%)
Mutual labels: egg, egg-plugin
Egg Oauth2 Server
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Stars: ✭ 174 (-22.32%)
Mutual labels: egg, egg-plugin
Egg Router Plus
The missing router feature for eggjs
Stars: ✭ 117 (-47.77%)
Mutual labels: egg, egg-plugin
Egg Restfulapi
🏅 基于Egg.js 2.0 & {mongoose,jwt}RESTful API 模板,用于快速集成开发RESTful前后端分离的服务端。
Stars: ✭ 524 (+133.93%)
Mutual labels: egg, egg-plugin
Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-79.02%)
Mutual labels: egg, egg-plugin
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+120.09%)
Mutual labels: egg, egg-plugin
Egg View React Ssr
Egg React Server Side Render (SSR) Plugin
Stars: ✭ 55 (-75.45%)
Mutual labels: egg, egg-plugin
egg-validate
Validate plugin for egg.
See parameter for more information such as custom rule.
Install
$ npm i egg-validate --save
Usage
// config/plugin.js
exports.validate = {
enable: true,
package: 'egg-validate',
};
Configurations
egg-validate support all parameter's configurations, check parameter documents to get more infomations.
// config/config.default.js
exports.validate = {
// convert: false,
// validateRoot: false,
};
Validate Request Body
// 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;
Extend Rules
- app.js
app.validator.addRule('jsonString', (rule, value) => {
try {
JSON.parse(value);
} catch (err) {
return 'must be json string';
}
});
Questions & Suggestions
Please open an issue here.
License
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].