在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:xpepermint/koa-strong-params开源软件地址:https://github.com/xpepermint/koa-strong-params开源编程语言:JavaScript 100.0%开源软件介绍:koa-strong-paramsRails-style implementation of strong parameters for Koa. The middleware adds the You should consider using koa-qs and koa-bodyparser packages together with InstallationInstall the npm package.
Attach the middleware. var koa = require('koa');
var params = require('koa-strong-params');
var app = koa();
app.use(params()); Examplevar koa = require('koa');
var params = require('koa-strong-params');
var bodyparser = require('koa-bodyparser');
var qs = require('koa-qs')
var app = koa();
qs(app); // required for nested query string objects
app.use(bodyparser()); // required for params to include request body objects
app.use(params());
app.use(function *() {
// all available params
this.body = this.params.all();
// -> { id: '13', name: 'Bob', age: '13', email: '[email protected]', address: { country: 'US', street: '261 West' }}
// only selected params
this.body = this.params.only('name', 'age');
// -> { name: 'Bob', age: '13' }
// all params except those provided
this.body = this.params.except('name', 'id', 'address');
// -> { id: '13', age: '13', email: '[email protected]' }
// all params of a sub-object
this.body = this.params.require('address').all();
// -> { country: 'US', street: '261 West' }
// only selected params + some merged attributes
this.body = this.params.merge({ badge: 'coder' }).only('name');
// -> { name: 'Bob', badge: 'coder' }
});
app.listen(3001); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论