You’ve installed xh. Now let’s get you productive fast. This guide covers GET/POST/Header/Session/Download/curl translation — everything you need for daily API work.nn
nn
Basic Requests
nn
GET — the simplest start
nn
xh httpbin.org/getnnnColored JSON back in milliseconds. No -X GET needed.nn
Auto-detected Method
nn
# Bare URL = GETnxh https://httpbin.org/jsonnn# With URL paramsnxh https://httpbin.org/get name==Tom page==1nnn
POST with JSON Body
nn
xh post httpbin.org/post name=Tom age:=26nnnNote the difference: name=Tom (string) vs age:=26 (:= forces JSON number type).nn
PUT / PATCH / DELETE
nn
xh put httpbin.org/put name=Updatednxh patch httpbin.org/patch name=Patchednxh delete httpbin.org/deletennn
nn
Headers and Query Parameters
nn
Custom Headers
nn
# Single headernxh httpbin.org/get user-agent:MyApp/1.0nn# Multiple headersnxh httpbin.org/get n accept:application/json n x-api-key:secret123nnnHeader name followed by a colon :. Empty value? Just write content-type: with nothing after it.nn
URL Query Parameters (no more hand-written ? and &)
nn
# Instead of https://httpbin.org/get?page=2&sort=descnxh get httpbin.org/get page==2 sort==descnnnThis alone makes xh worth using.nn
nn
Form Submissions and File Uploads
nn
Form Data (application/x-www-form-urlencoded)
nn
xh -f post httpbin.org/post username=admin password=123456nnn-f is shorthand for --form.nn
Upload a File
nn
# @ reads file contentsnxh post httpbin.org/post document@report.pdfnnn
nn
Sessions — Keep Login State
nn
# First: login (Session saves cookies)nxh post :8080/login username=admin password=secret --session=loginnn# Subsequent requests reuse the same sessionnxh get :8080/api/profile --session=loginnnnIt’s like browser “remember me” — no manual cookie extraction.nn
nn
Downloads and Output Control
nn
Download to File
nn
xh -d https://httpbin.org/json -o response.jsonnnn-d is --download, -o is --output.nn
Body-Only or Headers-Only
nn
# Body onlynxh httpbin.org/get -bnn# Headers onlynxh httpbin.org/get -hnn# Custom format (metadata + headers + body)nxh httpbin.org/get -p hmn# m = metadata, h = headers, b = bodynnn
nn
Most Useful: –curl Translation
nnTranslate any xh command to an equivalent curl command:nn
xh post httpbin.org/post name=Tom age:=26 --curlnnnOutputs:nn
curl -X POST https://httpbin.org/post n -H "Content-Type: application/json" n -d '{"Name":"Tom","age":26}'nnnHandy for sharing with curl-only colleagues. Or construct without sending:nn
xh post :8080/api/users name=admin --offline --curlnnnnn
nn
SSL and Timeout Control
nn
Skip SSL Verification (dev environments)
nn
xh https://expired-cert.example.com/get --verify=nonnn
Set a Timeout
nn
xh httpbin.org/delay/5 --timeout=3nnn3-second timeout. Because waiting is boring.nn
nn
Quick Reference
nn
| Scenario | Command |
|---|---|
| GET | xh url |
| POST JSON | xh post url k=v |
| URL params | xh url k==v |
| Header | xh url name:value |
| Form | xh -f post url k=v |
| Download | xh -d url -o file |
| Session | xh url --session=sess.txt |
| curl translate | xh url --curl |
| Offline construct | xh url --offline |
| Skip SSL | xh url --verify=no |
nn
nn
Next Steps
nnThat’s the full picture: intro, Linux install, macOS install, and usage guide — all published on the blog. Share the English version with international colleagues or Linux friends.nnQuestions? Comments welcome.
Comments