9

命令行 API 调试工具: HTTPie & jq

 2 years ago
source link: https://fann.im/blog/2015/01/20/httpie-and-jq/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

命令行 API 调试工具: HTTPie & jq

Jan 20, 2015

  • HTTPie: a CLI, cURL-like tool for humans.
  • jq: a command-line JSON processor.

HTTPie 类似 cURL,更简单易用,jq 用来解析 JSON,一起配合使用做 API 开发调试非常方便:

  1. GET: http :9090/api/test
  2. POST: http -f post --session=fann :9090/api/login' user=fannheyward passwd=passwd
  3. GET with cookie: http --session=fann :9090/api/profile

  1. jq . - 格式化整个 JSON
  2. jq ".status" - 只显示 status 字段的值
  3. jq ". | {name: .name, icon: .icon}" - 重组 JSON,只显示 name&icon 字段
  4. jq ".[] | {name: .name}" - 遍历 JSON 数组,只显示每个元素的 name 字段

更多高级用法参考各自文档。

Was this page helpful?


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK