如何使用 Postman Collection 生成代码如何使用、代码、Postman、Collection

2023-09-07 11:10:32 作者:父母就是我们拼的最好理由

我知道可以从单个 Postman 请求中生成代码片段,但我无法为整个集合找到类似的功能.我也知道有像 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