
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
koa-params-validator
Advanced tools
Koa2 请求参数校验中间件, 基于 easy-object-validator 校验
npm i -S koa-params-validator
const validator = require('koa-params-validator')
const app = new require('koa')();
// validator() 返回一个Koa2中间件方法,未通过校验的将返回 500 状态码
app.use(validator({
query: {
keyword: validator.string().isRequire()
},
body: {
data: validator.arrayOf(validator.object())
}
}))
// 在路由中使用
route.post('/login', validator({
body: {
username: validator.string().isRequire()
password: validator.string().isRequire()
}
}, {
statsu: 200,
state:{
success: false,
data: '用户名或密码不能为空'
}
}), (ctx) => {
// login...
})
校验规则的API与 easy-object-validator 完全一致,请直接参考其用法
validator
: Function(options, invalidMixinContext)options
校验规则,请参考 easy-object-validatorinvalidMixinContext
[可选] 未通过校验时将这个对象混合到Koa的context对象上,默认 status: 500, 默认 message: 'The parameter is invalid'FAQs
Koa请求参数校验中间件
We found that koa-params-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.