snippetbashModeratepending
curl recipes -- common HTTP debugging patterns
Viewed 0 times
curlPOSTheadersJSONauthtimingverbose
terminallinuxmacos
Problem
Need to debug HTTP APIs from the command line. Common tasks: send JSON, follow redirects, inspect headers, test auth, upload files, measure timing.
Solution
Essential curl flags and recipes for API debugging and testing.
Code Snippets
Essential curl recipes for API debugging
# POST JSON
curl -X POST https://api.example.com/users \
-H 'Content-Type: application/json' \
-d '{"name": "Alice", "email": "alice@example.com"}'
# Show response headers + body
curl -i https://api.example.com/health
# Verbose (full request/response)
curl -v https://api.example.com/health
# Bearer token auth
curl -H 'Authorization: Bearer TOKEN' https://api.example.com/me
# Follow redirects
curl -L https://short.url/abc
# Timing breakdown
curl -o /dev/null -s -w '
DNS: %{time_namelookup}s
Connect: %{time_connect}s
TLS: %{time_appconnect}s
TTFB: %{time_starttransfer}s
Total: %{time_total}s
' https://api.example.com
# Upload file
curl -F 'file=@photo.jpg' https://api.example.com/upload
# Save response to file
curl -o response.json https://api.example.com/dataRevisions (0)
No revisions yet.