cURL Command Line Recipes & API Cheat Sheet
Production cURL command recipes: sending JSON payloads, custom headers, bearer tokens, file uploads, following redirects, SSL flags, and curl timing variables with 1-click copy.
Basic Requests & Output (4 commands)
curl https://api.example.com/data
Performs simple HTTP GET request and streams response body to stdout.
curl -i https://example.com
Includes HTTP response status line and headers alongside the response body.
curl -L https://short.url/link
Follows HTTP redirects (301 Moved Permanently, 302 Found) automatically.
curl -v https://api.example.com
Verbose mode: outputs full TLS handshake, request headers (>), and response headers (<).
Headers, Auth & Cookies (4 commands)
curl -H "Authorization: Bearer <token>" -H "Accept: application/json" https://api.example.com
Sends custom HTTP headers with request.
curl -u "username:password" https://api.example.com/admin
Sends Basic HTTP Authentication header (base64 encoded automatically).
curl -b "session_id=xyz123" https://example.com/profile
Sends cookies with request.
curl -A "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)" https://example.com
Sets custom User-Agent header (emulates mobile safari, chrome, or bot).
POST Requests & Payloads (4 commands)
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "role": "admin"}'
Submits JSON payload via HTTP POST method.
curl -X POST https://api.example.com/upload \
-H "Content-Type: application/json" \
-d @payload.json
Reads JSON request payload directly from a local disk file using @filename.
curl -F "avatar=@/path/photo.png" -F "user_id=42" https://api.example.com/profile
Sends multipart/form-data upload including binary file and form fields.
curl --data-urlencode "query=search term with spaces" https://example.com/search
URL-encodes form data parameters automatically before transmission.
File Downloads & Resumes (3 commands)
curl -O https://example.com/releases/v1.0.tar.gz
Downloads remote resource and saves locally using the remote filename.
curl -C - -O https://example.com/large_dataset.iso
Resumes an interrupted file download where it left off using byte ranges.
curl --limit-rate 500k -O https://example.com/big_file.zip
Throttles download bandwidth speed to maximum 500 KB/s.
Diagnostics & Latency Timing (2 commands)
curl -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" -o /dev/null -s https://example.com
Detailed HTTP timing breakdown: measures DNS resolution, TCP handshake, TLS, and TTFB.
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/health
Extracts and outputs only the numeric HTTP response status code (e.g. 200, 404, 502).
SSL & Security Options (3 commands)
curl -k https://self-signed.local
Insecure mode: ignores invalid, expired, or self-signed SSL/TLS certificates.
curl --resolve example.com:443:198.51.100.15 https://example.com
Forces curl to connect to an explicit IP address, bypassing public DNS lookup.
curl -x socks5://127.0.0.1:1080 https://api.example.com
Routes all curl traffic through an HTTP or SOCKS5 proxy server.