cURL Commands Cheat Sheet

The most used curl commands for web requests, downloads and APIs


Basic requests

curl https://example.com                 # GET a page
curl -I https://example.com              # headers only
curl -i https://example.com              # headers and body
curl -L https://example.com              # follow redirects
curl -o page.html https://example.com    # save output to a file
curl -O https://example.com/file.zip     # download with remote name

Sending data

curl -d "name=value&other=1" https://example.com/form
curl -X POST -H "Content-Type: application/json" \
     -d '{"key":"value"}' https://api.example.com
curl -F "file=@/path/to/file" https://example.com/upload
curl -X PUT -d '{"updated":true}' https://api.example.com/item/1
curl -X DELETE https://api.example.com/item/1

Authentication

curl -u user:pass https://example.com                       # basic auth
curl -H "Authorization: Bearer TOKEN" https://api.example.com  # bearer token
curl -H "X-API-Key: YOUR_KEY" https://api.example.com        # api key header

Debugging and timing

curl -v https://example.com               # verbose output
curl -w "%{time_total}s\n" -o /dev/null https://example.com   # time the request
curl -w "%{http_code}\n" -o /dev/null -s https://example.com  # status code only
curl -A "Mozilla/5.0" https://example.com                     # custom user agent
curl --resolve example.com:443:1.2.3.4 https://example.com    # hit a specific IP