xh

ducaaleMIT活跃维护

用 Rust 写的命令行 HTTP 客户端,语法友好、启动快,适合在终端里发请求调试 API 或做接口测试。

Friendly and fast tool for sending HTTP requests

v0.26.3发布于 2026-10-21 07:47 UTC8,177star +4 / 7 天156fork同步于 2026-11-10 11:31 UTC

怎么上手

由 README 提炼,执行前请确认
curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh | sh
硬件要求按 README 说明

README 未说明,纯命令行工具,无 GPU 或显存要求

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

HTTPie 的 Rust 重写版,命令行发 HTTP 请求更快更友好

用 Rust 写的命令行 HTTP 客户端,语法友好、启动快,适合在终端里发请求调试 API 或做接口测试。

核心能力

  • 兼容 HTTPie 的 request-item 语法设置头、参数和 JSON 体
  • 用 =、:=、==、@、: 等符号快速构造请求
  • 支持下载、断点续传、会话和重定向跟随
  • 可输出 curl 命令翻译并生成 shell 补全
  • 支持 HTTP/2、HTTP/3 及 Unix socket 连接

容易踩的坑

用 Cargo 安装需 Rust 1.85 或更高版本;Debian/Ubuntu 需 13/25.04 以上且仅支持 native-tls;默认启用 --check-status,服务器返回错误码时进程会以非零状态退出

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v0.26.3
  1. v0.26.3最新正式版2026-10-21 · 2026-10-21 07:47 UTC

    Security fixes

    • Upgrade rustls-webpki to v0.103.16 and webpki-root-certs to v1.0.10

    Features

    • Detect and error on incomplete downloads, see #487 (@AkshayDhola)
  2. v0.26.22026-07-26 · 2026-07-26 14:22 UTC
    查看更新说明

    Bug fixes

    • Fix --auth ignoring credentials when the username is empty (e.g. -a :password), see #467 (@upuddu)
    • Decode all frames in concatenated zstd response bodies, see #470 (@snowyukitty)
  3. v0.26.12026-06-19 · 2026-06-19 22:41 UTC
    查看更新说明

    Features

    • Pretty-print XML responses, see #450 (@o1x3)
    • Add experimental HTTP message signatures (RFC 9421) support, see #448 (@zuisong)

    Other

    • Upgrade to reqwest v0.13, see #441 (@ducaale)
  4. v0.25.32025-12-16 · 2025-12-16 22:10 UTC
    查看更新说明

    Features

    • Add colors to --help/-h, see #432 (@starsep)

    Bug fixes

    • Don't fail on error code 416 if resuming download, see #434 (@simonomi)

    Other

    • Upgrade brotli to latest version, see #438 (@ducaale)
  5. v0.25.02025-09-19 · 2025-09-19 21:29 UTC
    查看更新说明

    Features

    • Add --unix-socket for calling Unix Domain Sockets, see #427 (@ducaale)
    • Support binding to interface name on macOS, see #421 (@ducaale)
    • Add experimental HTTP/3 support, see #425 (@ducaale)

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    xh

    Version info Packaging status

    xh is a friendly and fast tool for sending HTTP requests. It reimplements as much as possible of HTTPie's excellent design, with a focus on improved performance.

    asciicast

    Installation

    via cURL (Linux & macOS)

    curl -sfL https://raw.githubusercontent.com/ducaale/xh/master/install.sh | sh
    

    via Powershell (Windows)

    iwr -useb https://raw.githubusercontent.com/ducaale/xh/master/install.ps1 | iex
    

    via a package manager

    OSMethodCommand
    AnyCargo*cargo install xh --locked
    AnyHuberhuber install xh
    AnyMisemise use xh --global
    Android (Termux)pkgpkg install xh
    Android (Magisk/KernelSU)MMRL**mmrl install xhhttp
    Alpine Linuxapk***apk add xh
    Arch LinuxPacmanpacman -S xh
    Debian & UbuntuApt****sudo apt install xh
    FedoraCopr*****sudo dnf install xh
    FreeBSDFreshPortspkg install xh
    NetBSDpkgsrcpkgin install xh
    Linux & macOSNixpkgsnix-env -iA nixpkgs.xh
    Linux & macOSFloxflox install xh
    Linux & macOSHomebrewbrew install xh
    Linux & macOSHermithermit install xh
    macOSMacPortssudo port install xh
    WindowsScoopscoop install xh
    WindowsChocolateychoco install xh
    WindowsWingetwinget add ducaale.xh

    * Make sure that you have Rust 1.85 or later installed

    ** You will need to install the MMRL CLI

    *** Built with native-tls only.

    **** Available since Debian 13 and Ubuntu 25.04. Built with native-tls only.

    ***** Enable COPR repo via sudo dnf copr enable ducaale/xh

    via pre-built binaries

    The release page contains prebuilt binaries for Linux, macOS and Windows.

    Usage

    Usage: xh [OPTIONS] <[METHOD] URL> [REQUEST_ITEM]...
    
    Arguments:
      <[METHOD] URL>     The request URL, preceded by an optional HTTP method
      [REQUEST_ITEM]...  Optional key-value pairs to be included in the request.
    
    Options:
      -j, --json                             (default) Serialize data items from the command line as a JSON object
      -f, --form                             Serialize data items from the command line as form fields
          --multipart                        Like --form, but force a multipart/form-data request even without files
          --raw <RAW>                        Pass raw request data without extra processing
          --pretty <STYLE>                   Controls output processing [possible values: all, colors, format, none]
          --format-options <FORMAT_OPTIONS>  Set output formatting options
      -s, --style <THEME>                    Output coloring style [possible values: auto, solarized, monokai, fruity]
          --response-charset <ENCODING>      Override the response encoding for terminal display purposes
          --response-mime <MIME_TYPE>        Override the response mime type for coloring and formatting for the terminal
      -p, --print <FORMAT>                   String specifying what the output should contain
      -h, --headers                          Print only the response headers. Shortcut for --print=h
      -b, --body                             Print only the response body. Shortcut for --print=b
      -m, --meta                             Print only the response metadata. Shortcut for --print=m
      -v, --verbose...                       Print the whole request as well as the response
          --debug                            Print full error stack traces and debug log messages
          --all                              Show any intermediary requests/responses while following redirects with --follow
      -P, --history-print <FORMAT>           The same as --print but applies only to intermediary requests/responses
      -q, --quiet...                         Do not print to stdout or stderr
      -S, --stream                           Always stream the response body
      -x, --compress...                      Content compressed (encoded) with Deflate algorithm
      -o, --output <FILE>                    Save output to FILE instead of stdout
      -d, --download                         Download the body to a file instead of printing it
      -c, --continue                         Resume an interrupted download. Requires --download and --output
          --session <FILE>                   Create, or reuse and update a session
          --session-read-only <FILE>         Create or read a session without updating it from the request/response exchange
      -A, --auth-type <AUTH_TYPE>            Specify the auth mechanism [possible values: basic, bearer, digest]
      -a, --auth <USER[:PASS] | TOKEN>       Authenticate as USER with PASS (-A basic|digest) or with TOKEN (-A bearer)
          --ignore-netrc                     Do not use credentials from .netrc
          --offline                          Construct HTTP requests without sending them anywhere
          --check-status                     (default) Exit with an error status code if the server replies with an error
      -F, --follow                           Do follow redirects
          --max-redirects <NUM>              Number of redirects to follow. Only respected if --follow is used
          --timeout <SEC>                    Connection timeout of the request
          --proxy <PROTOCOL:URL>             Use a proxy for a protocol. For example: --proxy https:http://proxy.host:8080
          --verify <VERIFY>                  If "no", skip SSL verification. If a file path, use it as a CA bundle
          --cert <FILE>                      Use a client side certificate for SSL
          --cert-key <FILE>                  A private key file to use with --cert
          --ssl <VERSION>                    Force a particular TLS version [possible values: auto, tls1, tls1.1, tls1.2, tls1.3]
          --https                            Make HTTPS requests if not specified in the URL
          --http-version <VERSION>           HTTP version to use [possible values: 1.0, 1.1, 2, 2-prior-knowledge, 3-prior-knowledge]
          --resolve <HOST:ADDRESS>           Override DNS resolution for specific domain to a custom IP
          --interface <NAME>                 Bind to a network interface or local IP address
      -4, --ipv4                             Resolve hostname to ipv4 addresses only
      -6, --ipv6                             Resolve hostname to ipv6 addresses only
          --unix-socket <FILE>               Connect using a Unix domain socket
      -I, --ignore-stdin                     Do not attempt to read stdin
          --curl                             Print a translation to a curl command
          --curl-long                        Use the long versions of curl's flags
          --generate <KIND>                  Generate shell completions or man pages
          --help                             Print help
      -V, --version                          Print version
    
    Each option can be reset with a --no-OPTION argument.
    

    Run xh help or man xh for more detailed information.

    Request Items

    xh uses HTTPie's request-item syntax to set headers, request body, query string, etc.

    • =/:= for setting the request body's JSON or form fields (= for strings and := for other JSON types).
    • == for adding query strings.
    • @ for including files in multipart requests e.g [email protected] or [email protected];type=image/jpeg;filename=goodbye.jpg.
    • : for adding or removing headers e.g connection:keep-alive or connection:.
    • ; for including headers with empty values e.g header-without-value;.

    An @ prefix can be used to read a value from a file. For example: x-api-key:@api-key.txt.

    The request body can also be read from standard input, or from a file using @filename.

    To construct a complex JSON object, a JSON path can be used as a key e.g app[container][0][id]=090-5. For more information on this syntax, refer to https://httpie.io/docs/cli/nested-json.

    Shorthand form for URLs

    Similar to HTTPie, specifying the scheme portion of the request URL is optional, and a leading colon works as shorthand for localhost. :8000 is equivalent to localhost:8000, and :/path is equivalent to localhost/path.

    URLs can have a leading :// which allows quickly converting a URL into a valid xh or HTTPie command. For example http://httpbin.org/json becomes http ://httpbin.org/json.

    xh http://localhost:3000/users # resolves to http://localhost:3000/users
    xh localhost:3000/users        # resolves to http://localhost:3000/users
    xh :3000/users                 # resolves to http://localhost:3000/users
    xh :/users                     # resolves to http://localhost:80/users
    xh example.com                 # resolves to http://example.com
    xh ://example.com              # resolves to http://example.com
    

    Making HTTPS requests by default

    xh will default to HTTPS scheme if the binary name is one of xhs, https, or xhttps. If you have installed xh via a package manager, both xh and xhs should be available by default. Otherwise, you need to create one like this:

    cd /path/to/xh && ln -s ./xh ./xhs
    xh httpbin.org/get  # resolves to http://httpbin.org/get
    xhs httpbin.org/get # resolves to https://httpbin.org/get
    

    Strict compatibility mode

    If xh is invoked as http or https (by renaming the binary), or if the XH_HTTPIE_COMPAT_MODE environment variable is set, it will run in HTTPie compatibility mode. The only current difference is that --check-status is not enabled by default.

    Examples

    # Send a GET request
    xh httpbin.org/json
    
    # Send a POST request with body {"name": "ahmed", "age": 24}
    xh httpbin.org/post name=ahmed age:=24
    
    # Send a GET request with querystring id=5&sort=true
    xh get httpbin.org/json id==5 sort==true
    
    # Send a GET request and include a header named x-api-key with value 12345
    xh get httpbin.org/json x-api-key:12345
    
    # Send a POST request with body read from stdin.
    echo "[1, 2, 3]" | xh post httpbin.org/post
    
    # Send a PUT request and pipe the result to less
    xh put httpbin.org/put id:=49 age:=25 | less
    
    # Download and save to res.json
    xh -d httpbin.org/json -o res.json
    
    # Make a request with a custom user agent
    xh httpbin.org/get user-agent:foobar
    

    How xh compares to HTTPie

    Advantages

    • Improved startup speed.
    • Available as a single statically linked binary that's easy to install and carry around.
    • HTTP/2 support.
    • Builtin translation to curl commands with the --curl flag.
    • Short, cheatsheet-style output from --help. (For longer output, pass help.)

    Disadvantages

    • Not all of HTTPie's features are implemented. (#4)
    • No plugin system.
    • General immaturity. HTTPie is old and well-tested.
    • Worse documentation.

    Similar or related Projects

    • curlie - frontend to cURL that adds the ease of use of httpie
    • httpie-go - httpie-like HTTP client written in Go
    • curl2httpie - convert command arguments between cURL and HTTPie