curl Tricks Most Developers Don't Know
DevToolKitcurl can do way more than just GET requests. Here are the tricks I use constantly that most people don't know about.
Time Any Request in Detail
curl -w "\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTLS: %{time_appconnect}s\nFirst byte: %{time_starttransfer}s\nTotal: %{time_total}s\nSize: %{size_download} bytes\n" -o /dev/null -s https://example.comThis is incredibly useful for debugging slow APIs. You can immediately see if the bottleneck is DNS, TLS handshake, or server processing.
Bypass DNS / Test Specific IPs
# Hit a specific IP but send the right Host header curl --resolve example.com:443:93.184.216.34 https://example.com # Test a staging server curl --resolve api.myapp.com:443:10.0.0.5 https://api.myapp.com/health
Retry with Backoff
# Retry 5 times with exponential backoff curl --retry 5 --retry-delay 2 --retry-max-time 60 https://api.example.com # Only retry on specific errors curl --retry 3 --retry-connrefused https://api.example.com
Auth Patterns
# Bearer token curl -H "Authorization: Bearer $TOKEN" https://api.example.com/me # Basic auth curl -u username:password https://api.example.com # API key in header curl -H "X-API-Key: abc123" https://api.example.com
Upload Files
# Upload a file curl -F "file=@photo.jpg" https://upload.example.com # Upload with metadata curl -F "file=@doc.pdf" -F "name=report" -F "public=true" https://api.example.com/upload # PUT a file curl -T backup.tar.gz https://storage.example.com/backups/
JSON Workflow
# POST JSON
curl -X POST https://api.example.com/users \
-H 'Content-Type: application/json' \
-d '{"name": "test", "email": "test@example.com"}'
# POST JSON from file
curl -X POST https://api.example.com/data \
-H 'Content-Type: application/json' \
-d @payload.json
# Pretty print response (pipe to jq)
curl -s https://api.example.com/data | jq .Download Like a Pro
# Download with progress bar curl -# -O https://example.com/big-file.iso # Resume broken download curl -C - -O https://example.com/big-file.iso # Download and rename curl -o myfile.zip https://example.com/download?id=123 # Rate limit download (100KB/s) curl --limit-rate 100K -O https://example.com/big-file.iso
Bonus: Create a .curlrc
# ~/.curlrc - defaults for every curl command -w "\n" # always add newline after output --connect-timeout 5 # don't wait forever -s # silent by default -S # but show errors
The -w flag for timing and --resolve for DNS bypass are the two tricks that save me the most time debugging production issues.