Getting Started with cURL
Back in the day, if you wanted to fetch data from a server, you'd write a script. Or open a browser. Or pray.
There was no simple way to just ask a server for something from your terminal.
Then came cURL — a command-line tool that lets you send requests to any server, instantly. It speaks HTTP, HTTPS, FTP, and about 25 other protocols. One tool. Every server.
Your First Request
Fetching a webpage is one command:
curl https://example.com
Output:
<!doctype html>
<html>
<head>
<title>Example Domain</title>
</head>
<body>
<h1>Example Domain</h1>
<p>This domain is for use in examples...</p>
</body>
</html>
That's it. You just talked to a server.
Understanding the Response
Want to see what's happening under the hood? Add -i to include headers:
curl -i https://example.com
Output:
HTTP/2 200
content-type: text/html; charset=UTF-8
content-length: 1256
date: Fri, 31 Jan 2026 10:00:00 GMT
<!doctype html>...
That 200 is the status code — it means success. The headers tell you content type, size, and server info.
Talking to APIs
Most APIs return JSON. Fetch it like this:
curl https://api.github.com/users/octocat
Output:
{
"login": "octocat",
"id": 583231,
"type": "User",
"name": "The Octocat",
"company": "@github",
"followers": 15000
}
GET vs POST — The Two Methods You Need
GET — Fetch data (default):
curl https://api.example.com/users
POST — Send data:
curl -X POST https://httpbin.org/post -d "name=tanish&role=developer"
Output:
{
"form": {
"name": "tanish",
"role": "developer"
}
}
Sending JSON Data
Modern APIs expect JSON. Use -H to set headers:
curl -X POST https://httpbin.org/post \
-H "Content-Type: application/json" \
-d '{"name": "tanish", "role": "developer"}'
Useful Flags
| Flag | What It Does |
|---|---|
-i | Include response headers |
-I | Fetch headers only (HEAD request) |
-X | Specify HTTP method (POST, PUT, DELETE) |
-H | Add custom header |
-d | Send data in request body |
-o | Save output to file |
-s | Silent mode (no progress bar) |
-L | Follow redirects |
Common Beginner Mistakes
- Forgetting
https://in the URL - Missing
-X POSTwhen sending data - Not using
-H "Content-Type: application/json"for JSON APIs - Forgetting
-Lwhen a URL redirects
Quick Note
If you're into modern shells, xonsh can replace cURL with native Python syntax. Worth exploring.
cURL turns your terminal into a conversation with any server on the internet. Master it, and you'll debug APIs faster than anyone with a GUI.