HTTP Client Tools Cheat Sheet
Every developer needs to make HTTP requests from the command line — testing APIs, debugging integrations, automating workflows, and diagnosing production issues. This cheat sheet covers the tools you need: curl for precision, httpie for readability, Bruno for team workflows, and wget for downloads.
curl — The Swiss Army Knife
curl is installed on virtually every Unix system. It is ugly, powerful, and essential.
Request Methods
| Command | Description |
|---|---|
curl https://api.example.com/users | GET request (default) |
curl -X POST https://api.example.com/users | POST request |
curl -X PUT https://api.example.com/users/1 | PUT request |
curl -X PATCH https://api.example.com/users/1 | PATCH request |
curl -X DELETE https://api.example.com/users/1 | DELETE request |
curl -I https://example.com | HEAD request (headers only) |
curl -X OPTIONS https://api.example.com | OPTIONS request (CORS preflight) |
curl -X QUERY -H 'Content-Type: application/json' -d '{"status":"shipped"}' https://api.example.com/orders | QUERY request (safe read with a body) |
-d, -F and --json already switch the method to POST, so -X POST is optional with them. Avoid -X GET -d ... or -X HEAD: use -G and -I instead (with -X HEAD curl waits for a body that never comes).
Headers
# Set a single header
curl -H "Content-Type: application/json" https://api.example.com
# Set multiple headers
curl -H "Content-Type: application/json" \
-H "Authorization: Bearer eyJ..." \
-H "X-Request-ID: abc123" \
https://api.example.com/users
# View response headers
curl -i https://example.com # Response headers + body
curl -I https://example.com # Response headers only
curl -v https://example.com # Full verbose (request + response headers)
curl -s -D - -o /dev/null https://example.com # Dump headers of a GET (not HEAD) to stdout
curl -s -o /dev/null -w '%header{content-type}\n' https://example.com # One response header (7.84+)
# Remove a header curl adds by default, or send it empty
curl -H "User-Agent:" https://example.com # removes it
curl -H "X-Empty;" https://example.com # sends "X-Empty:" with no value
Sending Data
# JSON body
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
# JSON shortcut (curl 7.82+): sets Content-Type and Accept to application/json and POSTs
curl --json '{"name": "Alice"}' https://api.example.com/users
curl --json @payload.json https://api.example.com/users
jq -n --arg n "$NAME" '{name: $n}' | curl --json @- https://api.example.com/users # build JSON safely from shell vars
# JSON from file
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d @payload.json
# -d @file strips newlines and carriage returns; use --data-binary @file to send the file byte-for-byte
# Query string built and URL-encoded by curl (GET)
curl -G https://api.example.com/search \
--data-urlencode "q=hello world" \
--data-urlencode "tag=c++"
curl --url-query "q=hello world" https://api.example.com/search # curl 8.6+, works with any method
# Upload a file as the raw body (PUT), e.g. to a presigned S3 URL
curl -T ./backup.tar.gz "https://bucket.s3.amazonaws.com/backup.tar.gz?X-Amz-Signature=..."
# Body from stdin
echo '{"a":1}' | curl --json @- https://api.example.com/items
# Literal @ at the start of the body
curl --data-raw '@not-a-file' https://api.example.com
# Form data (application/x-www-form-urlencoded)
curl -X POST https://api.example.com/login \
-d "username=alice&password=secret"
# Multipart form (file upload)
curl -X POST https://api.example.com/upload \
-F "file=@document.pdf" \
-F "description=My document"
# Multiple files
curl -X POST https://api.example.com/upload \
-F "files=@file1.jpg" \
-F "files=@file2.jpg" \
-F "metadata={\"album\":\"vacation\"};type=application/json"
Authentication
# Basic auth
curl -u username:password https://api.example.com/protected
# Bearer token
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \
https://api.example.com/me
# API key in header
curl -H "X-API-Key: sk_live_abc123" https://api.example.com/data
# API key in query parameter
curl "https://api.example.com/data?api_key=sk_live_abc123"
# Client certificate
curl --cert client.pem --key client-key.pem https://secure.example.com
# Digest auth
curl --digest -u user:pass https://api.example.com/digest-protected
# Prompt for the password (keeps it out of shell history and `ps`)
curl -u username https://api.example.com/protected
# Bearer token shortcut
curl --oauth2-bearer "$TOKEN" https://api.example.com/me
# Credentials from ~/.netrc ("machine api.example.com login alice password s3cret")
curl -n https://api.example.com/protected
# AWS SigV4-signed request (curl 7.75+)
curl --aws-sigv4 "aws:amz:us-east-1:execute-api" \
-u "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
-H "x-amz-security-token: $AWS_SESSION_TOKEN" \
https://abc123.execute-api.us-east-1.amazonaws.com/prod/items
# Trust a private CA instead of using -k
curl --cacert ca.pem https://internal.example.com
Secrets passed as arguments are visible to other users in ps. For scripts, read them from a file: curl -H @headers.txt URL (one header per line, curl 7.55+) or -K config.txt.
Redirects and Cookies
# Follow redirects
curl -L https://example.com/redirect
# Follow redirects, limit to 5 hops
curl -L --max-redirs 5 https://example.com/redirect
# Save cookies to file
curl -c cookies.txt https://example.com/login \
-d "user=alice&pass=secret"
# Send saved cookies
curl -b cookies.txt https://example.com/dashboard
# Save and send cookies (full session)
curl -c cookies.txt -b cookies.txt https://example.com/api
Response Handling
# Save response to file
curl -o output.json https://api.example.com/data
# Save with remote filename
curl -O https://example.com/files/report.pdf
# Silent mode (no progress bar)
curl -s https://api.example.com/data
# Silent but show errors
curl -sS https://api.example.com/data
# Pretty-print JSON response
curl -s https://api.example.com/data | jq .
# Write response to file and stdout simultaneously
curl -s https://api.example.com/data | tee response.json | jq .
# Fail on HTTP errors (exit code 22 for 4xx/5xx) -- essential in scripts and CI
curl -fsSL https://example.com/install.sh -o install.sh
curl -sS --fail-with-body https://api.example.com/data # fail, but still print the error body (7.76+)
# Resume a partial download / skip if already downloaded
curl -C - -O https://example.com/big.iso
curl --skip-existing -O https://example.com/big.iso # 8.10+
# Several downloads in parallel
curl -Z -O https://example.com/a.zip -O https://example.com/b.zip
# Only download if changed (conditional GET)
curl -z local.json -o local.json https://api.example.com/data.json # If-Modified-Since from file mtime
curl --etag-save etag.txt --etag-compare etag.txt -o data.json https://api.example.com/data.json
# Status code and body in one request
response=$(curl -s -w '\n%{http_code}' https://api.example.com/data)
body=${response%$'\n'*}; status=${response##*$'\n'}
Timing and Debugging
# Show request/response timing breakdown
curl -s -o /dev/null -w "\
DNS: %{time_namelookup}s\n\
Connect: %{time_connect}s\n\
TLS: %{time_appconnect}s\n\
TTFB: %{time_starttransfer}s\n\
Total: %{time_total}s\n\
HTTP Code: %{http_code}\n\
Size: %{size_download} bytes\n" \
https://api.example.com/health
# Verbose mode (see full request/response)
curl -v https://api.example.com
# Trace to file (even more detail than -v)
curl --trace trace.log https://api.example.com
# Only check HTTP status code
curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health
# Set timeout
curl --connect-timeout 5 --max-time 30 https://slow-api.example.com
# Retry on failure
curl --retry 3 --retry-delay 2 https://flaky-api.example.com
# --retry only retries transient errors (timeouts, 408, 429, 500, 502, 503, 504).
# Add --retry-all-errors to retry anything, --retry-connrefused for "connection refused"
curl --retry 5 --retry-all-errors --retry-max-time 60 -f https://flaky-api.example.com
# Every -w variable as JSON (7.70+)
curl -s -o /dev/null -w '%{json}' https://api.example.com | jq .
# Keep a reusable timing format in a file
curl -s -o /dev/null -w @curl-format.txt https://api.example.com
# Force an HTTP version
curl --http1.1 https://example.com
curl --http2 https://example.com
curl --http3 https://example.com # needs a curl built with HTTP/3
# See the TLS certificate chain and negotiated protocol
curl -vI https://example.com 2>&1 | grep -E 'SSL|TLS|subject|issuer|expire|ALPN'
Proxy and Network
# Use HTTP proxy
curl -x http://proxy:8080 https://api.example.com
# Use SOCKS5 proxy
curl --socks5 localhost:9050 https://api.example.com
# Resolve hostname to specific IP (bypass DNS)
curl --resolve api.example.com:443:10.0.0.1 https://api.example.com
# Send requests for one host:port to another (test a new backend with the real Host/SNI)
curl --connect-to api.example.com:443:new-lb.example.com:443 https://api.example.com
# Talk to a server over a Unix socket (e.g. the Docker API)
curl --unix-socket /var/run/docker.sock http://localhost/containers/json
# Proxy settings from the environment are honoured: HTTPS_PROXY, HTTP_PROXY, NO_PROXY
curl --noproxy '*' https://internal.example.com # ignore them for one request
# Use specific network interface
curl --interface eth0 https://api.example.com
# Limit bandwidth
curl --limit-rate 100K https://example.com/large-file.zip -O
# Ignore SSL certificate errors (development only!)
curl -k https://self-signed.example.com
Never Use -k in Production Scripts
curl -k disables certificate verification, making connections vulnerable to man-in-the-middle attacks. If you need to trust a custom CA, use --cacert ca-bundle.pem instead.
curl Complete Reference Table
| Flag | Long Form | Description |
|---|---|---|
-X | --request | HTTP method |
-H | --header | Add request header |
-d | --data | Send data (POST body) |
--json | Send JSON body with JSON headers (7.82+) | |
--data-binary | Send data exactly as given (no newline stripping) | |
--data-urlencode | URL-encode the data | |
-G | --get | Put -d data in the query string, use GET |
-T | --upload-file | Upload a file (PUT) |
-f | --fail | Exit non-zero (22) on HTTP 4xx/5xx |
--fail-with-body | Like -f but keep the body | |
-D | --dump-header | Write response headers to a file (- for stdout) |
-C | --continue-at | Resume (-C - = auto) |
-Z | --parallel | Run transfers in parallel |
-K | --config | Read options from a file |
-n | --netrc | Read credentials from ~/.netrc |
-F | --form | Multipart form data |
-u | --user | Basic auth credentials |
-o | --output | Write to file |
-O | --remote-name | Save with remote filename |
-L | --location | Follow redirects |
-i | --include | Show response headers |
-I | --head | HEAD request |
-v | --verbose | Full verbose output |
-s | --silent | No progress meter |
-S | --show-error | Show error in silent mode |
-c | --cookie-jar | Save cookies to file |
-b | --cookie | Send cookies from file |
-k | --insecure | Skip TLS verification |
-w | --write-out | Custom output format |
--connect-timeout | Connection timeout (seconds) | |
--max-time | Total timeout (seconds) | |
--retry | Number of retries | |
--compressed | Request compressed response | |
-A | --user-agent | Set User-Agent header |
-e | --referer | Set Referer header |
-x | --proxy | Use a proxy |
--resolve | Pin host:port to an IP | |
--cacert | Trust this CA bundle | |
--retry-all-errors | Retry on any error (with --retry) | |
--url-query | Add URL-encoded query params (8.6+) |
Config File and Variables
# ~/.curlrc is read automatically (skip it with -q as the first argument)
# Example per-project config, used with -K:
cat > api.curl <<'EOF'
header = "Authorization: Bearer TOKEN"
header = "Accept: application/json"
silent
show-error
fail-with-body
EOF
curl -K api.curl https://api.example.com/me
# Variables (8.3+): read env vars or files into the command line
curl --variable %TOKEN --expand-header 'Authorization: Bearer {{TOKEN}}' https://api.example.com/me
Convert from the Browser
In Chrome/Firefox DevTools > Network, right-click a request > Copy as cURL to get a ready-to-run command with all headers and cookies (strip the cookies before sharing it).
httpie — Human-Friendly HTTP
httpie (http command) provides a more readable syntax than curl, with automatic JSON formatting, syntax highlighting, and sensible defaults.
Installation
brew install httpie # macOS
pip install httpie # pip
sudo apt install httpie # Debian/Ubuntu
Basic Usage
# GET (default)
http https://api.example.com/users
# POST with JSON (automatic Content-Type: application/json)
http POST https://api.example.com/users name=Alice age:=30 admin:=true
# Note: := for non-string values (numbers, booleans, null)
# = for string values
# PUT
http PUT https://api.example.com/users/1 name=Alice
# DELETE
http DELETE https://api.example.com/users/1
httpie vs curl Comparison
| Task | curl | httpie |
|---|---|---|
| GET | curl https://api.example.com | http api.example.com |
| POST JSON | curl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' URL | http POST URL name=Alice |
| Auth | curl -H "Authorization: Bearer TOKEN" URL | http URL Authorization:"Bearer TOKEN" |
| Headers | curl -H "Accept: text/plain" URL | http URL Accept:text/plain |
| Form data | curl -d "name=Alice" URL | http -f POST URL name=Alice |
| Download | curl -O URL | http -d URL |
| Verbose | curl -v URL | http -v URL |
httpie Advanced Features
# Custom headers (Header:Value)
http api.example.com X-API-Key:abc123 Accept:application/xml
# Query parameters (==)
http api.example.com/search query==react page==1 limit==20
# Send JSON from file
http POST api.example.com/users < user.json
# Bearer auth (built-in)
http -A bearer -a eyJhbGci... api.example.com/me
# Session persistence (like cookies)
http --session=logged-in POST api.example.com/login user=alice pass=secret
http --session=logged-in api.example.com/dashboard # Cookies sent automatically
# Download with progress bar
http --download https://example.com/file.zip
# Output only headers
http --headers api.example.com
# Output only body
http --body api.example.com
# Offline mode (print the request that would be sent)
http --offline POST api.example.com name=Alice
# Nested JSON (httpie 3.0+)
http POST api.example.com/users user[name]=Alice user[tags][]=admin user[tags][]=dev
# -> {"user": {"name": "Alice", "tags": ["admin", "dev"]}}
# Raw JSON value from a literal or file
http POST api.example.com/items meta:='{"draft": true}' config:=@config.json
# File upload (multipart)
http -f POST api.example.com/upload file@./photo.jpg title="Vacation"
# Raw body
http POST api.example.com/raw --raw 'plain text body'
# Fail on 4xx/5xx in scripts (exit codes 4 and 5)
http --check-status --ignore-stdin api.example.com/health
# Follow redirects, verbose, pretty off
http --follow -v --pretty=none api.example.com
# localhost shorthand
http :3000/users # = http://localhost:3000/users
# HTTPS by default
https api.example.com # `https` command, or http --default-scheme=https
| Separator | Meaning | Example |
|---|---|---|
: | Header | Accept:application/json |
== | Query param | page==2 |
= | JSON string field (form field with -f) | name=Alice |
:= | Raw JSON value | age:=30, tags:='["a"]' |
@ | File upload field (with -f) | file@./a.png |
=@ / :=@ | Field value from file (string / raw JSON) | bio=@bio.txt |
Use --ignore-stdin in scripts and CI: when stdin is not a terminal, httpie otherwise tries to read the request body from it and can hang.
httpie Is Great for Exploration
Use httpie when you are exploring an API interactively — the colored output and intuitive syntax save time. Use curl when you are writing scripts or need precise control — curl is installed everywhere and has more flags.
Bruno — API Client for Teams
Bruno is an open-source API client that stores collections as files (not in the cloud). Collections can be version-controlled with git — unlike Postman, which stores everything in its cloud.
Why Bruno Over Postman
| Feature | Bruno | Postman |
|---|---|---|
| Storage | Local filesystem (git-friendly) | Postman cloud |
| Offline | Fully offline | Limited offline |
| Version control | Collections are files — commit to git | Cloud sync only |
| Pricing | Free and open source | Free tier limited, paid for teams |
| Privacy | Data never leaves your machine | Data on Postman servers |
| Scripting | JavaScript (pre/post request) | JavaScript (similar) |
| Environments | .env files or Bruno environment files | Cloud-synced environments |
Bruno Collection Structure
api-collection/
bruno.json # Collection config
environments/
development.bru # Dev environment variables
production.bru # Prod environment variables
users/
get-users.bru # GET /users
create-user.bru # POST /users
get-user-by-id.bru # GET /users/:id
orders/
create-order.bru # POST /orders
list-orders.bru # GET /orders
Bruno Request Format (.bru)
meta {
name: Create User
type: http
seq: 2
}
post {
url: {{baseUrl}}/api/users
body: json
auth: bearer
}
auth:bearer {
token: {{authToken}}
}
headers {
Content-Type: application/json
X-Request-ID: {{$guid}}
}
body:json {
{
"name": "Alice",
"email": "alice@example.com",
"role": "admin"
}
}
script:pre-request {
const token = await bru.getVar("authToken");
if (!token) {
// Auto-login if no token
const res = await bru.runRequest("auth/login");
bru.setVar("authToken", res.body.token);
}
}
tests {
test("status is 201", () => {
expect(res.status).to.equal(201);
});
test("response has user id", () => {
expect(res.body.id).to.be.a("string");
bru.setVar("userId", res.body.id);
});
}
Running Bruno from CLI
# Install CLI
npm install -g @usebruno/cli
# Run entire collection
bru run --env development
# Run specific folder
bru run users/ --env development
# Run with custom environment file
bru run --env-file .env.local
# Override or inject one variable
bru run --env development --env-var authToken="$TOKEN"
# CI reports
bru run --env ci --reporter-junit results.xml --reporter-html results.html
# Stop on the first failure
bru run --env ci --bail
bru run must be executed from the collection's root folder (where bruno.json lives). Keep secrets out of git: mark environment variables as secret in the app, or put them in a gitignored .env file at the collection root and reference them as process.env.API_KEY inside double curly braces, like any other Bruno variable.
wget — Downloads and Mirroring
wget excels at downloading files — especially recursive downloads, mirroring websites, and resuming interrupted downloads.
Basic Downloads
| Command | Description |
|---|---|
wget https://example.com/file.zip | Download a file |
wget -O output.zip URL | Download with custom filename |
wget -P /tmp/ URL | Download to specific directory |
wget -c URL | Resume interrupted download |
wget -q URL | Quiet mode (no progress) |
wget -b URL | Download in background |
wget --limit-rate=500k URL | Limit download speed |
wget -qO- URL | Print to stdout (pipe into another command) |
wget --spider URL | Check that a URL exists without downloading (health checks) |
wget --header="Authorization: Bearer TOKEN" URL | Add a header |
wget --user=alice --ask-password URL | Basic auth with a password prompt |
wget -N URL | Only download if the remote file is newer |
wget --content-disposition URL | Use the filename the server suggests |
Some distros (e.g. Fedora 40+) now ship wget2 as wget. The common flags are the same; recursive mode is faster and downloads in parallel.
Multiple Downloads
# Download list of URLs from file
wget -i urls.txt
# Download multiple files
wget https://example.com/file1.zip https://example.com/file2.zip
# Download with retry
wget --tries=5 --waitretry=10 https://example.com/large-file.zip
Website Mirroring
# Mirror an entire website
wget --mirror \
--convert-links \
--adjust-extension \
--page-requisites \
--no-parent \
https://docs.example.com/
# Explanation:
# --mirror Recursive download, timestamping, infinite depth
# --convert-links Convert links for local viewing
# --adjust-extension Add .html to extensionless files
# --page-requisites Download CSS, images, etc.
# --no-parent Do not ascend to parent directory
# Download specific file types
wget -r -A "*.pdf" https://example.com/docs/
# Exclude specific paths
wget --mirror --exclude-directories=/archive https://example.com/
wget vs curl
| Feature | wget | curl |
|---|---|---|
| Recursive download | Built-in (-r, --mirror) | Not supported |
| Resume downloads | -c | -C - |
| Background download | -b | Not built-in |
| Protocol support | HTTP, HTTPS, FTP | HTTP, HTTPS, FTP, SFTP, SCP, LDAP, MQTT, and many more |
| API testing | Basic | Full-featured |
| Scripting | Download-focused | General HTTP client |
| Output control | Basic | Very flexible (-w format) |
Common Recipes
OAuth 2.0 Token Flow
# Step 0 (PKCE, required for public clients and recommended for all by OAuth 2.1 / RFC 9700)
code_verifier=$(openssl rand -base64 48 | tr -d '=+/\n' | cut -c1-64)
code_challenge=$(printf '%s' "$code_verifier" | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=\n')
# Step 1: Get authorization code (browser)
# User visits:
# https://auth.example.com/authorize?
# client_id=myapp&
# redirect_uri=http://localhost:3000/callback&
# response_type=code&
# scope=read+write&
# state=RANDOM_STATE&
# code_challenge=$code_challenge&
# code_challenge_method=S256
# With PKCE, add -d "code_verifier=$code_verifier" to the Step 2 request.
# Step 2: Exchange code for token
curl -s -X POST https://auth.example.com/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "code=AUTH_CODE_HERE" \
-d "client_id=myapp" \
-d "client_secret=SECRET" \
-d "redirect_uri=http://localhost:3000/callback" | jq .
# Step 3: Use the access token
curl -s -H "Authorization: Bearer ACCESS_TOKEN" \
https://api.example.com/me | jq .
# Step 4: Refresh token
curl -s -X POST https://auth.example.com/token \
-d "grant_type=refresh_token" \
-d "refresh_token=REFRESH_TOKEN" \
-d "client_id=myapp" \
-d "client_secret=SECRET" | jq .
# Machine-to-machine: client credentials grant (client auth via HTTP Basic)
curl -s -u "myapp:SECRET" https://auth.example.com/token \
-d "grant_type=client_credentials" \
-d "scope=read" | jq -r .access_token
# Grab the token into a variable and use it
TOKEN=$(curl -s -u "myapp:SECRET" https://auth.example.com/token \
-d grant_type=client_credentials | jq -r .access_token)
curl -s --oauth2-bearer "$TOKEN" https://api.example.com/me
# Decode a JWT's payload locally (no signature check!)
jq -R 'split(".") | .[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson' <<< "$TOKEN"
Multipart File Upload with Metadata
# Upload image with metadata
curl -X POST https://api.example.com/media \
-H "Authorization: Bearer TOKEN" \
-F "file=@photo.jpg;type=image/jpeg" \
-F "title=Vacation Photo" \
-F "tags=travel,beach" \
-F "metadata={\"location\":\"Maldives\",\"date\":\"2026-01-15\"};type=application/json"
# Upload multiple files with progress
curl -X POST https://api.example.com/batch-upload \
-H "Authorization: Bearer TOKEN" \
-F "files=@report-q1.pdf" \
-F "files=@report-q2.pdf" \
-F "files=@report-q3.pdf" \
--progress-bar
WebSocket Testing
# websocat — WebSocket client from command line
# Install: cargo install websocat OR brew install websocat
# Connect to WebSocket
websocat wss://echo.websocket.org
# Send a message and print responses
echo '{"type":"subscribe","channel":"orders"}' | \
websocat wss://api.example.com/ws
# WebSocket with auth header
websocat -H "Authorization: Bearer TOKEN" wss://api.example.com/ws
# curl understands ws:// and wss:// URLs (added in 7.86 as experimental, enabled by
# default since 8.11): connects, upgrades and prints received messages
curl --no-buffer wss://echo.websocket.org
# Manual upgrade handshake over HTTP(S): only checks that the server answers 101 Switching Protocols
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Sec-WebSocket-Version: 13" \
--header "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==" \
https://echo.websocket.org
Server-Sent Events (SSE) and Streaming
# -N disables buffering so events print as they arrive
curl -N -H "Accept: text/event-stream" https://api.example.com/events
# Streaming LLM-style API
curl -N --json '{"stream": true, "prompt": "hi"}' https://api.example.com/v1/generate
Health Check Script
#!/bin/bash
# health-check.sh — Check multiple endpoints
ENDPOINTS=(
"https://api.example.com/health"
"https://web.example.com"
"https://auth.example.com/health"
"https://cdn.example.com/status"
)
for url in "${ENDPOINTS[@]}"; do
# One request, two values (status 000 = no response: DNS, connect or timeout failure)
read -r code time < <(curl -s -o /dev/null -w "%{http_code} %{time_total}" --max-time 5 "$url")
if [ "$code" -ge 200 ] && [ "$code" -lt 300 ]; then
echo "[OK] $code ${time}s $url"
else
echo "[FAIL] $code ${time}s $url"
fi
done
API Response Comparison
# Compare responses from two environments
diff <(curl -s https://staging-api.example.com/users | jq -S .) \
<(curl -s https://prod-api.example.com/users | jq -S .)
# Monitor an endpoint continuously
watch -n 5 'curl -s -o /dev/null -w "HTTP %{http_code} in %{time_total}s" https://api.example.com/health'
Tool Selection Guide
graph TD
TASK["What are you doing?"]
QUICK["Quick API test<br/>or exploration?"]
SCRIPT["Writing a script<br/>or automation?"]
TEAM["Team API<br/>workflows?"]
DOWNLOAD["Downloading files<br/>or mirroring?"]
TASK --> QUICK -->|"Yes"| HTTPIE["httpie<br/>Best readability"]
TASK --> SCRIPT -->|"Yes"| CURL["curl<br/>Universal, scriptable"]
TASK --> TEAM -->|"Yes"| BRUNO["Bruno<br/>Git-friendly collections"]
TASK --> DOWNLOAD -->|"Yes"| WGET["wget<br/>Recursive, resumable"]
style HTTPIE fill:#059669,color:#fff
style CURL fill:#0891b2,color:#fff
style BRUNO fill:#d97706,color:#fff
style WGET fill:#7c3aed,color:#fff
Related Pages
- Terminal Productivity — tmux, fzf, ripgrep, jq
- Bash Cheat Sheet — Shell scripting
- Git Cheat Sheet — Version control
- Docker Cheat Sheet — Container operations
- GraphQL Cheat Sheet — GraphQL query reference
Test Yourself
-
What curl flag follows HTTP redirects?
-Lor--location -
How do you send a JSON body with curl?
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL -
What curl flag shows the full request and response headers?
-vor--verbose -
How do you get only the HTTP status code from a curl request?
curl -s -o /dev/null -w "%{http_code}" URL -
What httpie syntax sends a non-string value (number or boolean)? Use
:=instead of=:age:=30,active:=true -
How do you upload a file with curl using multipart form data?
curl -F "file=@document.pdf" URL -
What wget flag resumes an interrupted download?
-c -
How do you save and reuse cookies across curl requests?
-c cookies.txtto save,-b cookies.txtto send. -
What is Bruno's key advantage over Postman? Collections are stored as local files (git-friendly) instead of in the cloud.
-
What curl flag sets a maximum total timeout for the request?
--max-time 30
Common Gotchas
curl -kdisables TLS verification. This makes you vulnerable to man-in-the-middle attacks. Use--cacert ca-bundle.pemfor custom CAs instead.- Forgetting
-sin scripts. Without silent mode, curl prints a progress bar that clutters your script output. Use-sSfor silent with errors. - httpie adds
Content-Type: application/jsonby default for POST. If your API expects form data, you must use-fflag:http -f POST URL field=value. - wget
--mirrorwithout--no-parent. Without it, wget follows links to parent directories and may download the entire site, not just the section you wanted. - curl exits 0 on HTTP 404 and 500. Without
-f/--fail-with-body, a failed API call looks like success toset -eand CI. Combine with-sS:curl -fsS. -dmangles files.-d @filestrips newlines; use--data-binary @filefor anything that isn't a one-line form body.-ddefaults toapplication/x-www-form-urlencoded. Sending JSON with-dbut noContent-Typeheader makes many servers reject or misparse it. Use--json.- Unquoted URLs with
&or?. The shell backgrounds the command at&or globs?/[]. Always single-quote URLs with query strings (and use-gto turn off curl's own[]{}globbing). - Status
000.-w '%{http_code}'prints000when there was no HTTP response at all (DNS failure, refused connection, timeout). Check curl's exit code too. -Ldrops the method and body on 301/302/303. curl switches POST to GET on those redirects, like browsers. Use--post301/--post302or have the server send 307/308.- Credentials leak through redirects and history. curl only resends
-ucredentials to the same host after a redirect unless you pass--location-trusted; tokens in-Hon the command line still end up in shell history.
One-Liner Summary
curl is the universal HTTP client for scripting, httpie is the human-friendly alternative for exploration, Bruno is the git-friendly API client for teams, and wget is the champion for recursive downloads.