Blog curl tricks every web developer should know
curl tricks every web developer should know
TL;DR curl handles most HTTP debugging from the terminal. Learn a few flags: -i to see headers, -X and -d for methods and bodies, -H for headers, -L to follow redirects, and -w for timing. It is faster than opening a tool for a quick check.
When I want to know what an endpoint actually returns, I reach for curl before anything else. No app to open, no tab to load, just a line in the terminal. A few flags cover almost everything you need.
See the full response
curl -i https://api.example.com/status # headers + body
curl -I https://api.example.com/status # headers only (HEAD)
-i includes the response headers, so you see the status code, content type, and caching in one shot. -I fetches just the headers.
Send methods and bodies
curl -X POST \
-H "Content-Type: application/json" \
-d '{"name":"test"}' \
https://api.example.com/items
-d sends a body and makes curl default to POST. Set the method explicitly with -X when you need PUT, PATCH, or DELETE. -H adds headers, including auth:
curl -H "Authorization: Bearer $TOKEN" https://api.example.com/me
Follow redirects
curl -L https://example.com
By default curl prints the redirect response instead of following it. -L follows the chain to the final page, which is what you usually want when checking a URL.
Time a request
curl -o /dev/null -s -w "time_total: %{time_total}s\n" https://example.com
-w prints chosen variables after the request. time_total tells you how long it took, and there are variables for DNS, connect, and time-to-first-byte when you want to find where a slow request spends its time.
Save and inspect
curl -o page.html https://example.com # save to a file
curl -s https://api.example.com/data | jq # pipe JSON into jq
-s silences the progress meter so piping stays clean.
Why it beats reaching for a tool
The value of curl is speed of thought. When a request misbehaves, one line tells you the status, the headers, and the body without breaking your flow to open something heavier. Learn these few flags and curl becomes the fastest way to answer "what does this endpoint actually do?"
FAQ
How do I send JSON with curl?
Set the content-type header and pass the body with -d: curl -H 'Content-Type: application/json' -d '{"key":"value"}' URL. curl defaults to POST when you include a body, or set the method explicitly with -X.
How do I see the response headers?
Use -i to include the response headers with the body, or -I to fetch only the headers with a HEAD request. Both are quick ways to check status codes, redirects, and caching headers.
How do I follow redirects?
Add -L. By default curl shows you the redirect response instead of following it. With -L it follows the chain to the final destination, which is usually what you want when testing a URL.