当前位置:网站首页>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语言版本和GCC版本
- 安全狗云原生安全能力全面亮相全球数字经济大会暨ISC互联网安全大会
- 解决登录vCenter提示“当前网站安全证书不受信任“
- Nacos下载与安装
- pyspark --- count the mode of multiple columns and return it at once
- 现货黄金分析的主要流派
- El - table column filter functions, control columns show and hide (effect and easy to implement full marks)
- MySQL 流程控制
- 华为设备BFD配置命令
- 1066 Root of AVL Tree // AVL平衡二叉搜索树模板
猜你喜欢
随机推荐
华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
我国有关信息方面的法律法规
信息学奥赛一本通T1448:深搜的剪枝技巧 电路维修
Chrome configuration samesite=none method
CISP-PTE Zhenti Demonstration
【多线程进阶】--- 常见锁策略,CAS,synchronized底层工作原理,JUC,线程安全的集合类,死锁
6.nodejs--promise、async-await
从学生到职场的转变
Shell脚本之一键安装mysql
DIFM network, rounding and repetition
pgaudit 的安装使用《postgresql》
Pinned Articles-
第五章:指令集
C语言版本和GCC版本
被数据分析重塑的5个行业
spark中Repartition 和 Coalesce 区别
mysql慢查询优化
测试用例设计方法之因果图详解
关于任命韩文弢博士代理NOI科学委员会主席的公告
Basic syntax of MySQL DDL and DML and DQL












