如何使用Postman Collection生成代码 [英] How to generate code using Postman Collection

查看:69
本文介绍了如何使用Postman Collection生成代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以根据邮递员的单个请求生成代码段,但找不到整个集合的类似功能.
我也知道,有一些工具,例如 newman ,用于以Postman Collection 2.1 json格式运行导出的馆藏.

I'm aware it is possible to generate code snippets from individual Postman requests, but I can't find similar functionality for a entire collection.
I also know that there are tools like newman for running an exported collection in Postman Collection 2.1 json format.

但是我特别要寻找的是一个从集合或Postman Collection 2.1 json格式的导出集合中生成 bash 代码的工具.这样,我不使用Postman的同事可以复制API请求.

But specifically what I'm looking for is a tool that generates bash code from a collection or from a exported collection in Postman Collection 2.1 json format. This way my co-workers who don't use Postman can replicate the API requests.

此选项在Postman中可用吗?我只是想念它,还是有任何工具可以做到这一点?

Is this option available in Postman and I'm just missing it or are there any tools that do this?

推荐答案

我结束了使用 Postman SDK postman-code-gen 创建我从Postman导出的Postman Collections中的代码片段.

I ended using the Postman SDK and postman-code-gen to create code snippets from Postman Collections that I exported from Postman.

不太确定为什么Postman尚未提供此功能,但是我做了一个简单的CLI工具来做到这一点: https://github.com/arashout/postman-collection-gen

Not really sure why this feature isn't provided already by Postman, but I made a simple CLI tool that does it: https://github.com/arashout/postman-collection-gen

# cURL request generation
node main.js -c example_collection.json

# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153&c1=APSC160&c2=CHEM154&version_key=1.2'
# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153'


# How to generate other languages:
node main.js -c example_collection.json -l shell,httpie
node main.js -c example_collection.json -l Swift,URLSession

这篇关于如何使用Postman Collection生成代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆