cURL is the Swiss Army knife of the internet. But most developers only use curl URL and call it a day.
Here are 9 tricks that took my API debugging from frustrating to effortless.
1. Pretty-Print JSON Responses
curl -s https://api.github.com/users/torvalds | python3 -m json.tool
Or with jq:
curl -s https://api.github.com/users/torvalds | jq '.name, .public_repos'
No more squinting at wall-of-text JSON.
2. See Full Request/Response Headers
curl -v https://httpbin.org/get 2>&1 | head -20
The -v flag shows DNS resolution, TLS handshake, all headers. Use -I for headers only:
curl -I https://dev.to
3. POST JSON Data
curl -X POST https://httpbin.org/post \
-H "Content-Type: application/json" \
-d '{"name": "Alex", "role": "developer"}'
Forget Postman for quick tests.
4. Follow Redirects
curl -L https://bit.ly/some-link
Without -L, cURL stops at 301/302. Debug redirect chains:
curl -L -v https://short.link 2>&1 | grep "< location"
5. Download With Progress Bar
curl -# -O https://example.com/large-file.zip
Resume interrupted downloads:
curl -C - -O https://example.com/large-file.zip
6. API Timing (My Daily Driver)
curl -o /dev/null -s -w "DNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" https://api.example.com/health
I run this every morning against production APIs. If TTFB spikes above 500ms, something is wrong.
7. Custom Headers
curl -H "Authorization: Bearer TOKEN" \
-H "Accept: application/json" \
https://api.example.com/data
Stack as many -H flags as you need.
8. Upload Files
curl -F "file=@/path/to/photo.jpg" \
-F "description=Profile picture" \
https://api.example.com/upload
9. Save and Reuse Cookies
# Save cookies
curl -c cookies.txt https://example.com/login -d "user=me&pass=secret"
# Use saved cookies
curl -b cookies.txt https://example.com/dashboard
Perfect for testing authenticated endpoints.
Bonus: My cURL Aliases
alias jcurl='curl -s | jq .'
alias hcurl='curl -I'
alias tcurl='curl -o /dev/null -s -w "Total: %{time_total}s\n"'
What is your most-used cURL flag?
Drop your favorite one-liner in the comments. The weirder the better.
I write about developer tools, web scraping, and productivity. Follow for weekly tips.
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Top comments (0)