Interacting with REST APIs, testing web endpoints, and inspecting HTTP response headers from the Linux terminal often feels cumbersome when using curl due to verbose flag options, manual JSON quoting, and unformatted raw output streams. While tools like HTTPie improved user ergonomics, their Python runtime dependencies can introduce noticeable execution latency. The xh tool delivers the best of both worlds: a blazingly fast, standalone HTTP client written in Rust that replicates HTTPie’s intuitive human-friendly syntax with native speed and minimal resource usage.
Why Choose xh Over curl and HTTPie?
While curl remains indispensable for mission-critical bash scripting and low-level network automation, xh accelerates interactive command-line development and debugging through several key enhancements:
- Zero Runtime Dependencies: Compiled as a single static binary in Rust, starting up instantaneously without Python interpreter delays.
- Automatic Syntax Highlighting: Automatically formats and colourises JSON bodies, HTTP status codes, and response headers for effortless terminal reading.
- Intuitive Shorthand: Translates
key=valuepairs into structured JSON bodies andkey==valueparameters into URL query strings without manual JSON escaping. - Built-in Curl Translation: Features a built-in
--curlflag that converts anyxhcommand directly into an equivalentcurlcommand for documentation and automation sharing.
Installing xh on Linux Distributions
The xh binary is available across primary package managers and pre-built release archives.
Installing on Arch Linux
Arch Linux includes xh directly within its official repositories:
sudo pacman -S xh
Installing via Cargo (Any Distribution)
If you have Rust installed, compile and place xh directly onto your PATH:
cargo install xh
Installing via Snap or Homebrew
On Ubuntu and Debian systems, install using Snap:
sudo snap install xh
Alternatively, if Homebrew is configured on Linux:
brew install xh
Sending Basic GET Requests with xh
Performing a basic GET request requires only specifying the domain or URL. By default, xh automatically prepends the http:// scheme and uses localhost if only a port number is supplied:
xh httpbin.org/get
To query a local development server running on port 8000, simply type:
xh :8000/api/status
Adding Query String Parameters
To append query parameters to the URL without manual question mark and ampersand delimiters, use the double equal sign (==) separator:
xh httpbin.org/get page==2 limit==50 sort==desc
This automatically constructs and executes the request to httpbin.org/get?page=2&limit=50&sort=desc.
Sending JSON POST Requests
When sending POST requests, xh assumes JSON by default. Use single equal signs (=) to define key-value pairs:
xh POST httpbin.org/post name="Jane Smith" role="Engineer" active:=true
Notice the use of := for boolean or numeric values; xh parses raw types correctly as numbers or booleans instead of coercing them into strings.
Sending Custom Headers and Authentication
Adding headers and authentication credentials follows clean, legible conventions:
- Custom Headers: Use a colon separator:
xh httpbin.org/headers Authorization:"Bearer my_api_token" X-API-Version:2 - Basic Authentication: Pass user credentials using the
-aor--authflag:xh -a admin:secret123 httpbin.org/basic-auth/admin/secret123
Inspecting Headers and Converting to curl
When debugging headers or latency, utilise xh‘s flexible output filtering:
- Inspect Headers Only: Pass
-h(or--headers) to suppress the body payload:xh -h https://digitash.com - Print curl Equivalent: If you need to embed the exact command into a team README or shell script, pass
--curl:xh --curl POST api.example.com/items title="New Task" completed:=falseThis prints the complete corresponding
curl -X POST -H ...syntax straight to stdout without executing the network request.
Integrating xh into your daily terminal workflow eliminates syntax frustration and accelerates API development across all your Linux workstations.