You use Curl whether you know it or not, directly or indirectly curl is responsible for pretty much everything going around on the internet, curl is awesome and you really really should use it, unless you have really good reason not to (or if you're one of those folks who's scared of a terminal). This post in no way discourages the use of tools like Postman, Thunder Client, Rest Assured, and Insomnia. I'm just trying to shed light on this really cool thing I've been using for a while now.
Curl (cli tool) and libcurl (the library) essentially are "Client for URL". It was first put out in 1996 (insane), is a client side url transfer library.
A really cool thing about curl is, that it not only is a rest api testing tool, but it also supports a plethora of other protocols and operations. curl supports 28 different protocols, including but not limited to HTTP, HTTPS, IMAP, POP3, FTP, SMTP, SCP, GOPHER.
Curl is veryy versatile and you can use it to do many things, you can use it to download files over the internet, smoke test and use REST APIs, send emails programmatically, perform graphql operations, encoded form submissions, use for system observability (measure latency and other metrics) and so so so much more.
Curl is open source and comes pre-installed in most modern systems. there's a LOT you can do with curl and I'll try to convince you to use it more often by the end of this post.
Why use curl
Always there
Like i mentioned before curl comes pre installed on most modern systems (and is extremely easy to install if that's not the case on your system). This makes it easy start using without external tooling or complicated setups.
Just paste in the command bro
With larger projects dealing with multiple APIs and services it often times becomes so much more easy to have ready to paste snippets on your READMEs and PRs that you can just run on your system, as opposed to having to setup, onboard and manage teams on API testing GUI clients. Also gives you the added advantage of reviewable diffs on how your APIs change, if you'd ever need that.
Works well with CI/CD
Since its just commands you can run on a terminal, you can easily run them in Makefiles, Docker, GitHub Actions, Crons etc. This makes it a godsend for automations and workflows.
Composability
You can very easily compose curl outputs and pipe them into other commands like grep, awk, jq etc. this helps you pattern match and perform other useful operations on your api response.
Teaches HTTP, networking and other fundamentals
Once you start using curl, you'll inevitably start to get a better understanding of http, networking and other fundamentals cs concepts :p
Lets use some curl
1. Download files over the internet
You can download files from the internet or any machine in your network that allows you to
# Download (keep server filename), follow redirects
curl -LO https://example.com/files/report.zip
# Resume a broken download
curl -C - -O https://example.com/files/report.zip
# Retries + rate limit
curl -L --retry 5 --retry-all-errors --limit-rate 2M -O https://example.com/big.iso
2. Use and test REST APIs
You can pretty much do anything on here that you would want to do on something like postman
# Smoke test
curl -fsS --max-time 5 https://api.example.com/health
# GET with query params (urlencoded)
curl -sS -G https://api.example.com/users --data-urlencode 'q=alice'
# POST JSON
API=https://api.example.com TOKEN="$MY_TOKEN"
curl -sS -X POST "$API/users" \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"email":"a@b.com","name":"Alice"}'
# PATCH with a local JSON file
curl -sS -X PATCH "$API/users/123" -H "Content-Type: application/json" -d @update.json
3. Send emails programmatically
Instead of using heavy SDKs/libraries for emails, just use curl
curl --url 'smtps://smtp.example.com:465' --ssl-reqd \
--mail-from 'you@example.com' --mail-rcpt 'them@example.com' \
--user 'you@example.com:APP_PASSWORD' \
--upload-file - <<'EOF'
From: You <you@example.com>
To: Them <them@example.com>
Subject: Hello from curl
Hi! This was sent over SMTP using curl.
EOF
4. GraphQL works too
You can run graphql queries on curl too
TOKEN="$MY_TOKEN"
curl -sS https://api.example.com/graphql \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"query":"query($id:ID!){ user(id:$id){ id name } }","variables":{"id":"123"}}'
5. Encoded form submissions
# application/x-www-form-urlencoded (safe encoding of values)
curl -sS -X POST https://api.example.com/login \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=alice@example.com' \
--data-urlencode 'password=s3cr3t!'
# Classic form with multiple fields
curl -sS -X POST https://api.example.com/submit \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'color=blue&size=XL&newsletter=true'
6. System Observability
You can fetch key metrics from your service over curl, and automate with cron jobs and maintain some form of basic system observability with barely any effort
# Print key timings & status as one line (good for logs)
curl -o /dev/null -sS https://api.example.com/health \
-w 'code=%{http_code} dns=%{time_namelookup} tcp=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} bytes=%{size_download}\n'
# JSON-style metrics
curl -o /dev/null -sS https://api.example.com/health \
-w '{"code":"%{http_code}","dns":%{time_namelookup},"tcp":%{time_connect},"tls":%{time_appconnect},"ttfb":%{time_starttransfer},"total":%{time_total},"bytes":%{size_download}}\n'
7. Misc
here's few more use cases I wanted to show but couldn't throw into a different category
# Multipart upload (file + JSON metadata)
curl -sS https://api.example.com/upload \
-F 'file=@./photo.jpg' \
-F 'meta={"tag":"hero"};type=application/json'
# Override DNS for canary/staging without /etc/hosts
curl --resolve api.example.com:443:127.0.0.1 https://api.example.com/v2
# mTLS (client certs)
curl --cert client.crt --key client.key https://mtls.example.com
# Use a proxy (corp/lab env)
curl --proxy http://proxy.local:3128 -sS https://example.com
I hope you now see how cool of a tool curl is and want to use it more often in your projects and at work.
Here's a really cool curl resource, Everything curl
hi pss if you made this this far, you should consider subscribing to my blog. click here to do so.
