httpie (http / https)
HTTPie is a command-line HTTP client built for APIs, with two commands: http and https. A simple key=value syntax turns headers, query strings and JSON bodies into one-liners, and responses come back formatted and coloured, which makes it ideal for interactive API debugging.
167.1 Why is it used?
- Test REST/JSON APIs with short, readable commands: JSON is the default body format.
- The separator of each item decides whether it is a header, query parameter, string field or raw JSON value.
- Coloured, sorted, indented output; print exactly the parts you need (request/response headers/body).
- Sessions remember cookies, headers and auth between calls; downloads with resume like wget.
- Not built into any OS: apt/dnf install httpie or pip (Linux), brew install httpie (macOS), pip/choco/winget (Windows).
167.2 How it works
- Syntax: http [METHOD] URL [ITEM ...]; METHOD is optional (GET, or POST when data items are present).
- No scheme means http:// (https command: https://); :8000/path is shorthand for localhost:8000.
- Lab: client 192.168.187.20 (HTTPie 3.2.3, Requests 2.33.1), api.lab = 192.168.187.10 JSON echo server (:80, :443 lab CA, :8443 client cert required, :3128 proxy stub).
- HTTPie is built on Python Requests; output is pretty on a terminal and raw when piped.
- Step 1
1.http POST api.lab/echo X-Team:netops q==net name=asha
- Step 2
2.X-Team:netops becomes a header (single colon)
- Step 3
3.q==net becomes the query string ?q=net (double equals)
- Step 4
4.name=asha becomes the JSON body {"name": "asha"} (single equals)
- Step 5
5.Request goes to api.lab 192.168.187.10:80
- Step 6
6.Echo server replies 200 OK with JSON of what it received
167.3 METHOD and URL
- Only a URL: GET. A data item (name=asha): automatic POST. Method as first argument: DELETE, PUT...
- :8000/echo/x = localhost:8000, :/echo/home = localhost:80.
- https uses https:// by default; without the lab CA you get CERTIFICATE_VERIFY_FAILED.
http api.lab/echohttp -b api.lab/echo name=ashahttp -b DELETE api.lab/echo/items/42http -b :8000/echo/xhttps -b api.lab/echo$ http api.lab/echoHTTP/1.1 200 OKContent-Length: 195Content-Type: application/jsonServer: n167-api { "body_bytes": 0, "method": "GET", "path": "/echo"}$ http -b api.lab/echo name=asha "body": "{\"name\": \"asha\"}", "method": "POST",$ http -b DELETE api.lab/echo/items/42 "method": "DELETE", "path": "/echo/items/42"$ http -b :8000/echo/x "Host": "localhost:8000",$ https -b api.lab/echohttps: error: SSLError: HTTPSConnectionPool( host='api.lab', port=443): ... [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1010)167.4 Request items: the separator decides the type
- Header: (empty value) removes a default header; 'Header;' sends an empty header.
- port=443 sends the string "443"; port:=443 sends the number 443; admin:=true a boolean; tags:='["dns","tls"]' an array.
- -f form mode: field@file uploads a file (multipart), 'cv@report.txt;type=text/csv' sets its type.
- field=@file reads the file text into a string; field:=@file.json embeds the JSON object.
- Backslash escapes a separator: 'zone\:id=7' gives the key zone:id.
http -b api.lab/echo X-Team:netops User-Agent:lab/1.0http -p H api.lab/echo Accept: User-Agent: 'X-Empty;'http -b api.lab/echo search==httpie lang==enhttp -b POST api.lab/echo name=asha port=443http -b POST api.lab/echo port:=443 admin:=true tags:='["dns","tls"]'http -b POST api.lab/echo order:=@order.json$ http -p H api.lab/echo Accept: User-Agent: 'X-Empty;'GET /echo HTTP/1.1Accept-Encoding: gzip, deflateConnection: keep-aliveHost: api.labX-Empty:$ http -b api.lab/echo search==httpie lang==en "method": "GET", "path": "/echo?search=httpie&lang=en"$ http -b POST api.lab/echo name=asha port=443 "body": "{\"name\": \"asha\", \"port\": \"443\"}",$ http -b POST api.lab/echo port:=443 admin:=true \ tags:='["dns","tls"]' "body": "{\"port\": 443, \"admin\": true, \"tags\": [\"dns\", \"tls\"]}",$ http -b POST api.lab/echo order:=@order.json "body": "{\"order\": {\"item\": \"router\", \"qty\": 2}}",| Separator | Example | Becomes |
|---|---|---|
| : | X-Team:netops | Request header |
| == | search==httpie | URL query parameter |
| = | name=asha | JSON string field (form field with -f) |
| := | port:=443 | Raw JSON value (number, bool, array) |
| @ | cv@report.txt | File upload (with -f / --multipart) |
| =@ | note=@note.txt | String field from file text |
| :=@ | order:=@order.json | JSON value from a file |
167.5 Content types and raw body
- --json (default): Content-Type application/json and Accept application/json, */*;q=0.5.
- --form / -f: application/x-www-form-urlencoded; --multipart always multipart/form-data (--boundary=xoxo sets the boundary).
- --raw='text', piped stdin or @file send a raw body (a file gets Content-Type text/plain).
- -x compresses the body with deflate only if it gets smaller (1621 -> 195 bytes); -xx forces it (18 -> 26 bytes).
http -p HB --form POST api.lab/echo name=asha city=Punehttp -p HB --multipart --boundary=xoxo POST api.lab/echo name=ashahttp -b --raw='hello raw' POST api.lab/echohttp -b --pretty=format -x POST api.lab/echo @big.json | grep -E 'Content-(Encoding|Length)|_bytes'$ http -p HB --form POST api.lab/echo name=asha city=PuneAccept: */*Content-Length: 19Content-Type: application/x-www-form-urlencoded; charset=utf-8name=asha&city=Pune$ http -p HB --multipart --boundary=xoxo POST api.lab/echo name=ashaContent-Length: 71Content-Type: multipart/form-data; boundary=xoxo--xoxoContent-Disposition: form-data; name="name"asha--xoxo--$ http -b --raw='hello raw' POST api.lab/echo "body": "hello raw", "body_bytes": 9,$ http -b --pretty=format -x POST api.lab/echo @big.json | grep ... "body_bytes": 1621, "Content-Encoding": "deflate", "Content-Length": "195", "raw_bytes": 195167.6 Output processing and output options
- --pretty=all (colours + format, terminal default), colors, format (indent + sort), none (raw, default when piped).
- -s / --style picks a colour theme (auto, pie, monokai, solarized...); --sorted / --unsorted toggle sorting.
- --format-options json.indent:2,json.sort_keys:false; --response-mime=application/json treats a text/plain body as JSON; --response-charset=latin1 fixes decoding (output became "Grüße aus café Köln").
- -p chooses parts: H request headers, B request body, h response headers, b response body, m metadata (elapsed time).
- -v = whole request + response, -vv adds metadata; -q prints nothing except errors (a 404 is not an error).
- --all shows redirect hops; -o FILE saves; -d downloads with a progress bar; -dc resumes (206, Content-Range); --stream prints lines as they arrive.
http --pretty=none -b api.lab/plain-json --response-mime=application/jsonhttp -b --format-options json.indent:2,json.sort_keys:false api.lab/plain-json --response-mime=application/jsonhttp -p m api.lab/echohttp --all -F -p Hh api.lab/hop/2head -c 400 big.bin > part.binhttp -dc -o part.bin api.lab/big.bin$ http --pretty=none -b api.lab/plain-json ...{"zone":"lab","ok":true,"ids":[3,1,2]}$ http -b --format-options json.indent:2,json.sort_keys:false ... "zone": "lab", "ok": true, "ids": [ 3, 1, 2 ]$ http -p m api.lab/echoElapsed time: 0.029038414s$ http --all -F -p Hh api.lab/hop/2GET /hop/2 HTTP/1.1HTTP/1.1 302 FoundLocation: /hop/1GET /hop/1 HTTP/1.1Location: /echoGET /echo HTTP/1.1HTTP/1.1 200 OK$ http -dc -o part.bin api.lab/big.binHTTP/1.1 206 Partial ContentContent-Length: 600Content-Range: bytes 400-999/1000Downloading to part.binDone. 1.0 kB in 00:0.61070 (1.6 kB/s)| -p letter | Prints | Shortcut |
|---|---|---|
| H | Request headers | - |
| B | Request body | - |
| h | Response headers | -h |
| b | Response body | -b |
| m | Metadata (elapsed time) | -m |
| HBhb | Everything | -v (-vv adds m) |
167.7 Sessions and authentication
- --session=dev saves cookies, headers and auth to ~/.config/httpie/sessions/api.lab/dev.json; --session=./s.json uses a path.
- With the session /me says "session ok", without it "missing".
- --session-read-only uses a session but does not save new headers (X-Trace not stored).
- -a user:pass = Basic (default); -A digest handles the 401 challenge itself; -A bearer -a TOKEN sends a Bearer token.
- Credentials in ~/.netrc are used automatically; --ignore-netrc stops that (401 again).
http -b --session=dev api.lab/loginhttp -b --session=dev api.lab/mehttp -b api.lab/mehttp api.lab/basichttp -b -a asha:LabPass167 api.lab/basichttp -b -A bearer -a lab-token-167 api.lab/bearerhttp --auth-type$ http -b --session=dev api.lab/login{ "login": "ok" }$ http -b --session=dev api.lab/me{ "session": "ok"}$ http -b api.lab/me "session": "missing"$ http api.lab/basicHTTP/1.1 401 UnauthorizedWWW-Authenticate: Basic realm="api.lab"$ http -b -a asha:LabPass167 api.lab/basic "auth": "Basic", "user": "asha"$ http -b -A bearer -a lab-token-167 api.lab/bearer "auth": "Bearer", "scope": "read",$ http --auth-typeusage: http -A/--auth-type {basic, digest, bearer} [METHOD] URL ...error: argument --auth-type/-A: expected one argument167.8 Network options
- --offline builds and prints the request but sends nothing.
- --proxy=http:URL sends the absolute URL to the proxy (the stub echoed "GET http://api.lab/echo HTTP/1.1").
- -F follows redirects; --max-redirects=2 on 5 hops: "Too many redirects", exit 6.
- --max-headers=2 aborts when more headers arrive; --timeout=2 to an unused IP: "Request timed out", exit 2.
- --check-status turns HTTP status into exit codes: 3xx = 3, 4xx = 4, 5xx = 5.
- --path-as-is keeps /a/../b unchanged; --chunked sends Transfer-Encoding: chunked.
- Step 1
1.http --proxy=http:http://192.168.187.10:3128 api.lab/echo
- Step 2
2.Client sends GET http://api.lab/echo HTTP/1.1 (absolute URL) to :3128
- Step 3
3.Lab proxy stub echoes the request line, forwards nothing
- Step 4
4.http --timeout=2 192.168.187.99/echo
- Step 5
5.Nothing answers on the unused IP
- Step 6
6."Request timed out (2.0s)", exit 2
http --offline POST api.lab/echo a=1http -b --proxy=http:http://192.168.187.10:3128 api.lab/echohttp -F --max-redirects=2 api.lab/hop/5time http --timeout=2 192.168.187.99/echohttp --check-status -b api.lab/missing; echo code=$?http -b --path-as-is api.lab/echo/a/../b$ http --offline POST api.lab/echo a=1POST /echo HTTP/1.1Content-Length: 10Content-Type: application/jsonHost: api.lab { "a": "1"}$ http -b --proxy=http:http://192.168.187.10:3128 api.lab/echo "request_line": "GET http://api.lab/echo HTTP/1.1", "via": "n167 proxy stub (nothing forwarded)"$ http -F --max-redirects=2 api.lab/hop/5http: error: Too many redirects (--max-redirects=2).(exit 6)$ time http --timeout=2 192.168.187.99/echohttp: error: Request timed out (2.0s).Command exited with non-zero status 2$ http --check-status -b api.lab/missing; echo code=$? "error": "not found",code=4$ http -b --path-as-is api.lab/echo/a/../b "path": "/echo/a/../b"167.9 SSL/TLS
- --verify=no skips the check (lab/testing only); --verify=ca.crt verifies properly; REQUESTS_CA_BUNDLE does the same.
- --ssl=tls1.2 forces a version; --ciphers picks the cipher.
- Port 8443 wants a client cert: without it "TLSV13_ALERT_CERTIFICATE_REQUIRED"; --cert + --cert-key fixes it (--cert-key-pass for an encrypted key).
https -b --verify=/lab/ca.crt api.lab/echohttps -b --pretty=format --verify=/lab/ca.crt --ssl=tls1.2 --ciphers=ECDHE-RSA-AES128-GCM-SHA256 api.lab/echo | grep -A3 tlshttps -b --verify=/lab/ca.crt api.lab:8443/echohttps -b --pretty=format --verify=/lab/ca.crt --cert=client.crt --cert-key=client.key api.lab:8443/echo | grep -A8 tls$ https -b --verify=no api.lab/echo "tls": { "cipher": "TLS_AES_256_GCM_SHA384", "version": "TLSv1.3" }$ https ... --ssl=tls1.2 --ciphers=ECDHE-RSA-AES128-GCM-SHA256 ... "cipher": "ECDHE-RSA-AES128-GCM-SHA256",$ https -b --verify=/lab/ca.crt api.lab:8443/echohttps: error: SSLError: HTTPSConnectionPool(host='api.lab', port=8443): ... [SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl.c:2580)$ https ... --cert=client.crt --cert-key=client.key api.lab:8443/echo "client_cert": { "commonName": "client.lab", "organizationName": "n167 lab" },167.10 Troubleshooting and misc
- In scripts/cron stdin is not a terminal, so httpie reads it and a GET becomes a POST; -I / --ignore-stdin fixes it.
- --debug prints versions (HTTPie, Requests, Python) and environment; --traceback shows the full Python stack.
- --default-scheme=https changes the scheme for URLs without one; --no-<option> resets an option to default.
http -b api.lab/echo < /dev/nullhttp -b --ignore-stdin api.lab/echo < /dev/nullhttp --debug -b api.lab/echo 2>&1 | head -25$ http -b api.lab/echo < /dev/null "Content-Length": "0", "Content-Type": "application/json", "method": "POST",$ http -b --ignore-stdin api.lab/echo < /dev/null "body_bytes": 0, "method": "GET",$ http --debug -b api.lab/echo 2>&1 | head -25HTTPie 3.2.3Requests 2.33.1Pygments 2.18.0Python 3.12.13 (main, Apr 10 2026, 14:16:31)167.11 Common mistakes
- Expecting a non-zero exit on 404/500: httpie exits 0; add --check-status in scripts.
- Writing count=5 when the API wants a number: use count:=5.
- Running httpie from cron without -I: empty stdin turns GET into POST.
- Using --verify=no outside a lab: pass the CA file instead.
- Forgetting -f for file uploads: field@file needs form/multipart mode.
167.12 Interview tips
- httpie vs curl: httpie is API-first (JSON default, separators, coloured output); curl is installed everywhere and supports many more protocols. Debugging: httpie, scripts: curl.
- Separators: : header, == query, = string, := raw JSON, @ file.
- count:=5 sends {"count": 5}; count=5 sends {"count": "5"}.
- --check-status exit codes: 3 for 3xx, 4 for 4xx, 5 for 5xx; 2 timeout, 6 too many redirects.