Once you have xh installed, this article will get you up to speed quickly. It covers common scenarios like GET/POST/Headers/Sessions/Download/curl translation — read through and you’ll be able to use it in your daily work.


Basic Requests

GET — The Simplest Start

Bash
xh httpbin.org/get

Colorful JSON response instantly — no need to even write -X GET.

Auto-Detecting Method

Bash
# Bare URL defaults to GET
xh https://httpbin.org/json

# With URL parameters
xh https://httpbin.org/get name==Tom page==1

POST — JSON Body

Bash
xh post httpbin.org/post name=Tom age:=26

Note the difference between name=Tom (string) and age:=26 (number, := forces JSON type).

PUT / PATCH / DELETE

Bash
xh put httpbin.org/put name=Updated
xh patch httpbin.org/patch name=Patched
xh delete httpbin.org/delete

Headers and Query Parameters

Custom Headers

Bash
# Single Header
xh httpbin.org/get user-agent:MyApp/1.0

# Multiple Headers
xh httpbin.org/get 
  accept:application/json 
  x-api-key:secret123

Header names are followed by a colon :. For empty values, write content-type: (without a value).

URL Query Parameters (No Need to Manually Write ? and &)

Bash
# Instead of https://httpbin.org/get?page=2&sort=desc
xh get httpbin.org/get page==2 sort==desc

This design is much more comfortable than curl.


Form Submission and File Upload

Form (application/x-www-form-urlencoded)

Bash
xh -f post httpbin.org/post username=admin password=123456

-f is short for --form.

File Upload

Bash
# @ reads file content
xh post httpbin.org/post document@report.pdf

Sessions: Keeping Login State

Bash
# First login (Session will save cookies)
xh post :8080/login username=admin password=secret --session=login

# Subsequent requests reuse the same Session
xh get :8080/api/profile --session=login

This is like “remembering login state” in a browser — no need to manually grab cookies.


Downloading Files and Output Control

Download to File

Bash
xh -d https://httpbin.org/json -o response.json

-d is --download, -o is --output.

View Only Response Body or Only Headers

Bash
# Only body
xh httpbin.org/get -b

# Only headers
xh httpbin.org/get -h

# Custom output format
xh httpbin.org/get -p hm
# m = metadata, h = headers, b = body

Most Useful Feature: –curl Translation

Translate xh commands into curl for sharing with colleagues who use curl:

Bash
# See the translation
xh post httpbin.org/post name=Tom age:=26 --curl

Output:

Bash
curl -X POST https://httpbin.org/post 
  -H "Content-Type: application/json" 
  -d '{"name":"Tom","age":26}'

Or print it without sending (--offline):

Bash
xh post :8080/api/users name=admin --offline --curl

SSL and Timeout Control

Skip SSL Verification (Test Environments)

Bash
xh https://expired-cert.example.com/get --verify=no

Timeout Setting

Bash
xh httpbin.org/delay/5 --timeout=3

3-second timeout — for those with limited patience.


xh Session Login State

Quick Reference Table

Scenario Command
GET xh url
POST JSON xh post url k=v
URL Parameters xh url k==v
Headers xh url name:value
Form xh -f post url k=v
Download xh -d url -o file
Session xh url --session=sess.txt
Translate to curl xh url --curl
Offline Construction xh url --offline
Skip SSL xh url --verify=no

Next Steps

Installation and usage have both been covered. An English version of the usage guide is also available on the blog — feel free to share with international colleagues or Linux enthusiasts. Questions? Leave a comment.

Last modified: 2026年7月6日

Author

Comments

Write a Reply or Comment

Your email address will not be published.