当前位置:网站首页>Postman will return to the interface to generate a json file to the local
Postman will return to the interface to generate a json file to the local
2022-08-03 07:32:00 【Fan Xi】
postmanIn addition to the results returned by the interface can be【生成csv文件】It can also be generated locallyjson文件.具体操作如下:
The same mock interface returns bulk parameter values,测试代码如下:
@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {
@PostMapping("/testGetParams")
private BizResponse<List<WarehouseDto>> testGetParams() {
List<WarehouseDto> warehouseDtoList = new ArrayList<>();
WarehouseDto warehouseDto1 = new WarehouseDto();
warehouseDto1.setId(1L);
warehouseDto1.setDescription("test1");
warehouseDtoList.add(warehouseDto1);
WarehouseDto warehouseDto2 = new WarehouseDto();
warehouseDto2.setId(2L);
warehouseDto2.setDescription("test2");
warehouseDtoList.add(warehouseDto2);
return ResponseUtil.success(warehouseDtoList);
}
}
The data structure returned by this interface is as follows:
{ "status":1, "code":"10000", "data":[ { "id":1, "description":"test1" }, { "id":2, "description":"test2" } ] }
postman中新建request,And the test will request the return result to generatejson文件,步骤:
1、添加接口请求url以及请求参数Body

2、在Tests中添加以下代码:
var data = pm.response.json().data;//obtained this data:[ { "id":1, "description":"test1" }, { "id":2, "description":"test2" } ]
console.log(data);
var dataStr = '[';
for(var i=0;i<data.length;i++){
dataStr+= '{"id":' + data[i].id + ',"description":"' + data[i].description + '"}' + (i==data.length-1?'':',');
}
dataStr+= ']';//Only extract what needs to be generatedjson文件的属性值,assembled into an array
console.log(dataStr);
let opts = {
requestName: request.name || request.url,
fileExtension: 'json',//这个和csvThe file configuration is different
mode: 'writeFile',//这个和csvThe file configuration is different
uniqueIdentifier: false,
responseData: dataStr
};
pm.sendRequest({
url: 'http://localhost:3000/write',
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'raw',
raw: JSON.stringify(opts)
}
}, function (err, res) {
console.log(res);
});
The other is to startpostman本地服务,(Generated for referencecsvfile configure local service step).Calling the interface can see what is executed after the interface is calledwrite生成文件,在项目目录下C:\soft\ResponseToFile-Postman\Responses下可以看到生成的json文件
边栏推荐
- c现代方法16章基础
- RHCSA第四天
- 死锁的成因和对应的解决方案
- El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
- 链表之打基础--基本操作(必会)
- El - tree set using setCheckedNodessetCheckedKeys default check nodes, and a new check through setChecked specified node
- C语言实现通讯录功能(400行代码实现)
- 深入理解IO流(第一篇)
- MySQL - 触发器
- 1066 Root of AVL Tree // AVL平衡二叉搜索树模板
猜你喜欢
随机推荐
线程基础(二)
调用feign报错openfeign/feign-core/10.4.0/feign-core-10.4.0.jar
最新版图书馆招聘考试常考试题重点事业单位
商业智能BI业务分析思维:供应链分析 – 如何控制牛鞭效应(二)
请手撸5种常见限流算法!面试必备
【卫朋】硬件创业:营销与开发同行
解读 refresh 十二步骤
docker-compose部署mysql
现货黄金分析的主要流派
(十四)51单片机——LCD1602实现滚动效果
mongodb的shell脚本
【着色器实现HandDrawn简笔画抖动效果_Shader效果第十二篇】
CISP-PTE Zhenti Demonstration
qt学习之旅--MinGW编译FFmpeg(32bit)
解决登录vCenter提示“当前网站安全证书不受信任“
Sqoop 导入导出 Null 存储一致性问题
qt学习之旅--MinGW32编译opencv3.0.0
深入理解IO流(第一篇)
用代码构建UI界面
Embedding two implementations of the torch code











