DEV Community

Alex Spinov
Alex Spinov

Posted on

9 cURL Tricks Every Developer Should Know (I Use #6 Daily)

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
Enter fullscreen mode Exit fullscreen mode

Or with jq:

curl -s https://api.github.com/users/torvalds | jq '.name, .public_repos'
Enter fullscreen mode Exit fullscreen mode

No more squinting at wall-of-text JSON.


2. See Full Request/Response Headers

curl -v https://httpbin.org/get 2>&1 | head -20
Enter fullscreen mode Exit fullscreen mode

The -v flag shows DNS resolution, TLS handshake, all headers. Use -I for headers only:

curl -I https://dev.to
Enter fullscreen mode Exit fullscreen mode

3. POST JSON Data

curl -X POST https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -d '{"name": "Alex", "role": "developer"}'
Enter fullscreen mode Exit fullscreen mode

Forget Postman for quick tests.


4. Follow Redirects

curl -L https://bit.ly/some-link
Enter fullscreen mode Exit fullscreen mode

Without -L, cURL stops at 301/302. Debug redirect chains:

curl -L -v https://short.link 2>&1 | grep "< location"
Enter fullscreen mode Exit fullscreen mode

5. Download With Progress Bar

curl -# -O https://example.com/large-file.zip
Enter fullscreen mode Exit fullscreen mode

Resume interrupted downloads:

curl -C - -O https://example.com/large-file.zip
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"'
Enter fullscreen mode Exit fullscreen mode

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)