在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:nemtsov/koa-json-mask开源软件地址:https://github.com/nemtsov/koa-json-mask开源编程语言:JavaScript 100.0%开源软件介绍:koa-json-maskMiddleware allowing the client to mask / filter the response to only what they need,
reducing the amount of traffic over the wire using the If you've used the Google APIs, provided a The difference between Underneath, this middleware uses json-mask. Use it directly without this middleware if you need more flexibility. Installation
In order to use this plugin with the previous version of Koa using generator functions, please use version
Options
ExampleObject responsesScript: const Koa = require('koa');
const mask = require('koa-json-mask');
const app = new Koa();
app.use(mask());
app.use(async ctx => {
ctx.body = {
name: 'tobi',
packages: 5,
friends: ['abby', 'loki', 'jane'],
location: {
id: '342',
name: 'London'
}
};
});
app.listen(3000);
console.log('app listening on port 3000'); Response:
Array responsesScript: const Koa = require('koa');
const mask = require('koa-json-mask');
const app = new Koa();
app.use(mask());
app.use(async ctx => {
ctx.body = [
{
name: 'tobi',
packages: 5,
friends: ['abby', 'loki', 'jane'],
location: {
id: '342',
name: 'London'
}
},
{
name: 'loki',
packages: 2,
friends: ['loki', 'jane'],
location: {
id: '62',
name: 'New York'
}
}
];
});
app.listen(3000);
console.log('app listening on port 3000'); Response:
SyntaxThe syntax is loosely based on XPath:
More examplesFor more examples, take a look at the examples section of the json-mask README. LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论