HTTPie:38,200 GitHub 星
HTTPie 是面向 API 时代的现代命令行 HTTP 客户端,支持 JSON、着色输出、会话。兼容 Python、pip、Homebrew、Docker。
- ⭐ 42323
- Open Source
- BSD-3-Clause
- 更新于 2026-05-19
HTTPie(中文发音 “aitch-tee-tee-pie”)是为 API 时代设计的命令行 HTTP 客户端。拥有 38,200+ GitHub 星标,是 API 测试 CLI 类别最受欢迎的开发者工具。
本指南覆盖:HTTPie 配置、与 curl/wget 比较、性能基准、生产加固、限制分析。
什么是 HTTPie? #
HTTPie 是用 Python 编写的开源命令行 HTTP 客户端,专为人类友好而设计。提供 http 与 https 两个命令,使用自然语法创建任意 HTTP 请求,格式化着色终端输出。
工具为测试、调试、与 API 交互而生。不同于面向文件传输的通用工具,HTTPie 优化 API 开发的 read-eval-print 循环:
- JSON 支持:自动序列化、格式化、着色
- 会话持久化:保存 auth、headers、cookies
- 语法自然:
"Name:Value"对应Name: ValueHTTP 头
安装方法 #
pip 安装(通用) #
python -m pip install --upgrade pip wheel
python -m pip install httpie
http --version
Homebrew(macOS) #
brew install httpie
Debian/Ubuntu APT #
curl -SsL https://packages.httpie.io/deb/KEY.gpg | sudo gpg --dearmor -o /usr/share/keyrings/httpie.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/httpie.gpg] https://packages.httpie.io/deb ./" | sudo tee /etc/apt/sources.list.d/httpie.list > /dev/null
sudo apt update
sudo apt install httpie
Docker #
docker run --rm httpie/cli https://httpie.io/hello
alias http='docker run --rm -it --net=host httpie/cli'
常用用法 #
GET 请求 #
http GET https://api.github.com/repos/httpie/cli
POST JSON 请求 #
http POST api.example.com/users name="John Doe" age:=29 active:=true
带认证请求 #
http GET api.example.com/protected "Authorization:Bearer YOUR_TOKEN"
会话持久化 #
# 创建会话
http --session=prod api.example.com/login username=user password=pass
# 复用会话
http --session=prod api.example.com/dashboard
集成实践 #
与 jq 集成 #
# 提取 API 响应字段
http GET https://api.github.com/repos/httpie/cli | jq '.stargazers_count'
# 链式请求
http GET https://api.github.com/user | jq -r '.login' | http POST webhook.site/user=@-
生产脚本 #
#!/bin/bash
# CI/CD API 健康检查
if http --check-status --timeout=5 --ignore-stdin GET https://api.example.com/health; then
echo "服务正常"
else
echo "服务异常"
exit 1
fi
性能对比 #
| 工具 | 版本 | 80GB 传输时间 | 吞吐量 |
|---|---|---|---|
| curl | 7.51.0 | 25 秒 | 3,276 MB/s |
| HTTPie | 3.2.4 | 153 秒 | 535 MB/s |
结论:大文件传输 curl 更快。API 请求 HTTPie 开发体验更佳。
常见场景 #
微服务健康检查 #
for service in api-gateway user-service order-service; do
http --check-status --timeout=3 GET "http://$service.internal/health" && echo "✓ $service OK" || echo "✗ $service FAILED"
done
Webhook 测试 #
http POST https://webhook.site/your-uuid event=order.created 'order:={"id": 12345, "total": 99.99}'
限制分析 #
- 性能:Python/Requests 基础,无法匹配 curl C 实现
- HTTP/2/3:仅支持 HTTP/1.1
- Python 依赖:需要 Python 3.7+
建议:HTTPie 为 API 交互优化,curl/wget 更适合文件传输。
推荐基础设施 #
- DigitalOcean — 60 天 200 美元免费信用
- HTStack — 大陆低延迟香港 VPS
本指南引用 Binance、OKX、DigitalOcean、HTStack 链接赚取佣金。
💬 留言讨论