Configs2026年4月15日·1 分钟阅读

xh — Friendly and Fast HTTPie-Compatible HTTP Client in Rust

xh is a blazing-fast HTTP client with an HTTPie-compatible UX, written in Rust, shipping as a single static binary with built-in JSON syntax highlighting, forms, sessions, and HTTP/2.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
xh guide
安全暂存命令
npx -y tokrepo@latest install bc2fcb99-389d-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

TL;DR
Rust-powered HTTP client with HTTPie-compatible syntax, JSON highlighting, sessions, and HTTP/2 in a single static binary.
§01

What it is

xh is a command-line HTTP client written in Rust that provides an HTTPie-compatible user experience with better performance. It ships as a single static binary with built-in JSON syntax highlighting, form submission, session management, and HTTP/2 support. The syntax matches HTTPie, so existing HTTPie users can switch without relearning commands.

xh targets developers and API testers who want a fast, portable HTTP client for the terminal. Its single-binary distribution means no Python runtime dependency (unlike HTTPie) and near-instant startup times.

§02

How it saves time or tokens

xh starts faster than HTTPie because it is a compiled binary, not a Python script. For developers making dozens of API calls during a debugging session, the accumulated startup time savings are noticeable. The built-in JSON highlighting and formatting mean you do not need to pipe output through jq for readability. Session support persists cookies and auth across requests without manual header management.

§03

How to use

  1. Install xh:
brew install xh
  1. Make HTTP requests with readable syntax:
# GET with pretty JSON
xh httpbin.org/json

# POST JSON body with header
xh POST api.example.com/users name=alice role=admin \
   Authorization:'Bearer $TOKEN'

# Form submission
xh -f POST example.com/login username=admin password=secret
  1. Use sessions for persistent cookies:
xh --session=myapi POST api.example.com/login
xh --session=myapi GET api.example.com/profile
§04

Example

API testing workflow with xh:

# Test an API endpoint with JSON payload
xh POST https://api.example.com/v1/messages \
  content-type:application/json \
  model=claude-sonnet-4-20250514 \
  max_tokens:=1024 \
  messages:='[{"role":"user","content":"Hello"}]'

# Download a file
xh -d https://example.com/report.pdf -o report.pdf

# Follow redirects and show headers
xh -v --follow https://short.url/abc

The := syntax sends raw JSON values (numbers, arrays, booleans) without quoting.

§05

Related on TokRepo

§06

Common pitfalls

  • The = syntax sends string values; := sends raw JSON. Using = for a number sends it as a string, which may cause API validation errors.
  • Session files store cookies and auth tokens in plain text. Protect session files with appropriate filesystem permissions.
  • xh does not support HTTPie plugins. If you rely on HTTPie's plugin ecosystem, check whether xh covers your specific use case natively.
  • Always check the official documentation for the latest version-specific changes and migration guides before upgrading in production environments.
  • For team deployments, establish clear guidelines on configuration and usage patterns to ensure consistency across developers.

常见问题

Is xh a drop-in replacement for HTTPie?+

Yes for most use cases. xh supports HTTPie's syntax for headers, JSON bodies, form data, and authentication. Some advanced HTTPie plugins and features may not be available in xh.

Why use xh instead of curl?+

xh provides human-friendly syntax and formatted output by default. JSON is highlighted, headers are readable, and the request syntax is intuitive. curl provides more raw control but requires more flags and piping for readable output.

Does xh support HTTP/2?+

Yes. xh supports HTTP/2 natively without additional configuration. It negotiates the protocol version automatically with servers that support HTTP/2.

How does session management work?+

Sessions persist cookies, authentication, and custom headers across requests. Use --session=name to create or continue a session. Session data is stored in files that are reused on subsequent requests.

Can xh handle file uploads?+

Yes. xh supports multipart file uploads using the @ syntax. For example: xh -f POST api.example.com/upload file@report.pdf uploads the file as multipart form data.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产