控制台http api工具
desman的Python项目详细描述
德斯曼
Desman是控制台HTTP API请求工具。Desman使用.yml文件保存请求信息。也可以使用.yml文件中的环境文件来替换要请求的变量。
安装
PIP
pip install desman
Unix上的Docker like
Desman可以安装为运行Docker映像的.sh脚本:
sudo curl -L --fail https://raw.githubusercontent.com/kirillsulim/desman/master/scripts/run/run.sh -o /usr/local/bin/desman
sudo chmod +x /usr/local/bin/desman
脚本中的默认标记是最新的。如果要修复特定版本,请更改脚本中相应的变量。
停靠在Windows上
Desman可以安装为运行Docker映像的.ps1脚本。 Download script并设置所需的权限。 脚本中的默认标记是最新的。如果要修复特定版本,请更改脚本中相应的变量。
如何使用
简单请求
创建.yml文件,请求说明:
method: get url: http://host.com/
然后将文件路径传递给desman
desman path/to/file.yml
德斯曼把反应的主体打印到控制台上。
参数
的请求查询参数可以在url中传递
method: get url: http://host.com/?param=value
或单独通过
method: get url: http://host.com/ params: param: value
标题
可以在“标题”字段中传递标题
method: get url: http://host.com/ headers: Authorization: Bearer some-auth-token params: param: value
身体
可以在请求文件的body字段中传递正文内容
method: post url: http://host.com/post headers: Authorization: Bearer some-auth-token body: | { "stringField": "JSON value", "nestedObject": { "nestedField": [1, 2, 3] } }
输出参数
http响应的输出由以下可选参数控制:
-s
打印响应状态-H
打印响应堆-b
打印响应正文
如果没有传递这些参数,desman只打印响应的主体。
使用环境
所有请求文件都是Jinja2模板。
# request.yml method: post url: http://{{server.host}}:{{server.port}}/post headers: Authorization: Bearer {{my-token}} body: | { "stringField": "JSON value", "nestedObject": { "nestedField": [1, 2, 3] } }
从environment.yml文件中替换变量
# env.yml server: host: host.com port: 8080 my-token: "some-auth-token"
传入可选参数-e
desman -e env.yml request.yml
您可以使用许多环境文件。如果它们有相似的字段,desman将使用最后出现的值。
有许多环境文件
# env.yml server: host: host.com port: 8080 my-token: "some-auth-token"
# new-token.yml my-token: "new-token"
如果两者都作为
desman -e env.yml -e new-token.yml request.yml
请求将使用Authorization: Bearer new-token
头执行。