cURL for Beginners: Your First Step to Talking with Servers

If you've ever wondered how developers test APIs or fetch data from servers without opening a browser, the answer is often a simple tool called cURL. In this guide, we'll explore what cURL is, why it matters, and how you can start using it today.
What is cURL?
cURL (short for "Client URL") is a command-line tool that lets you send requests to servers and receive responses. Think of it as a way to have a conversation with a server using your terminal instead of a web browser.
Understanding Servers First
Before we dive into cURL, let's quickly understand what a server is. A server is simply a computer that stores information and responds to requests. When you visit a website, your browser sends a request to a server asking for a webpage, and the server sends back the HTML, images, and other files that make up that page.
┌─────────────────┐
│ Your Browser │
└────────┬────────┘
│
│ Request: "Show me google.com"
▼
┌─────────────────┐
│ Google Server │
└────────┬────────┘
│
│ Response: HTML, CSS, JS files
▼
┌─────────────────┐
│ Your Browser │
│ (Renders page) │
└─────────────────┘
What Does cURL Do?
cURL is essentially a messenger. Instead of clicking buttons in a browser, you type commands in your terminal to:
Fetch data from websites
Send data to servers
Test if an API is working correctly
Download files
Interact with web services
The beauty of cURL is its simplicity. You don't need a fancy interface or complicated setup. Just your terminal and a single command.
Let's Learn the Basics of cURL
Now that you understand what cURL is, let's dive into how to actually use it. We'll start with the simplest possible commands and gradually build your understanding.
Making Your First Request with cURL
Let's get hands-on! The simplest cURL command fetches a webpage, just like your browser does.
The Most Basic Command
Open your terminal and type:
curl https://google.com
Press Enter, and you'll see a bunch of HTML code scroll across your screen. Congratulations! You just made your first cURL request.
What just happened?
You told cURL to contact the server at google.com
The server sent back the HTML content of that webpage
cURL displayed the raw response body in your terminal—not a rendered webpage, but the actual markup code that browsers interpret
This is different from opening a page in Chrome. Your browser parses HTML, loads CSS, and executes JavaScript. cURL simply shows you the unrendered text response from the server.
Making It More Readable
The raw HTML can be overwhelming. Let's make it cleaner:
curl -I https://google.com
The -I flag tells cURL to only fetch the headers (metadata about the response) instead of the full content. You'll see something like:
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Mon, 20 Jan 2026 10:30:00 GMT
This is much easier to read! Let's understand what this means.
Understanding Request and Response
Every time you use cURL, you're creating a conversation between your computer and a server. This conversation has two parts: the request and the response.
The Request
When you type curl https://google.com, you're sending a request that includes:
Method: What you want to do (GET, POST, etc.)
URL: Where you're sending the request
Headers: Additional information about your request
Body: Data you're sending (for some types of requests)
The Response
The server sends back a response containing:
Status Code: A number indicating if the request succeeded
Headers: Information about the response
Body: The actual data (HTML, JSON, etc.)
Understanding Status Codes
Status codes tell you what happened with your request:
200: Success! Everything worked perfectly
404: Not Found - the page doesn't exist
500: Server Error - something went wrong on the server
403: Forbidden - you don't have permission to access this
To see the status code clearly, use the -i flag:
curl -i https://google.com
This shows both headers (including the status code) and the response body.

Using cURL to Talk to APIs
Now that you understand the basics, let's use cURL for its most common purpose: interacting with APIs.
What is an API?
An API is like a menu at a restaurant. Instead of going into the kitchen and making your own food, you look at the menu, order what you want, and the kitchen prepares it for you. Similarly, an API lets you request specific data from a server without needing to know how the server works internally.
Making a GET Request
GET requests are used to retrieve data. Let's use a free test API:
curl https://jsonplaceholder.typicode.com/posts/1
You'll get back something like:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident",
"body": "quia et suscipit\nsuscipit..."
}
This is JSON data, a common format for APIs.
Getting Multiple Items
Want to see all posts? Just change the URL:
curl https://jsonplaceholder.typicode.com/posts
This returns a list of all posts in JSON format.
Making a POST Request
POST requests send data to a server, typically to create new resources. Let's create a new blog post:
curl -X POST https://jsonplaceholder.typicode.com/posts \
-H "Content-Type: application/json" \
-d '{"title":"My First Post","body":"This is my content","userId":1}'
Breaking down each component:
-X POST: Specifies the HTTP method
REST APIs follow conventions: GET retrieves data (read), POST creates new resources (create), PUT updates existing data, and DELETE removes resources. Here, we're using POST because we're creating a new blog post.
-H "Content-Type: application/json": Sets the content type header
This header performs content negotiation with the server. Servers can accept various formats—JSON, XML, form data, plain text. Specifying application/json eliminates ambiguity, telling the server "I'm sending JSON, parse it accordingly." Without this header, the server might reject your request or misinterpret your data.
-d '{"title":"My First Post",...}': Provides the request body (payload)
The -d flag sends the message body—the actual data you're transmitting. Think of it as the content of your message. In a GET request, you're just asking for information (no body needed). In POST, you're delivering information (body required).
The server responds with the created post, including an ID it assigned.
Saving the Response to a File
Instead of displaying data in the terminal, you can save it:
curl https://jsonplaceholder.typicode.com/posts/1 -o post.json
Use the -o flag to save the response to a file named post.json.
Making JSON Readable with jq
Raw JSON output becomes unreadable for large responses. Pipe your cURL output through jq (a command-line JSON processor) for formatted results:
# Install jq first (varies by OS):
# Ubuntu/Debian: sudo apt-get install jq
# Mac: brew install jq
# Pretty-print JSON
curl https://jsonplaceholder.typicode.com/posts/1 | jq .
# Extract specific fields
curl https://jsonplaceholder.typicode.com/posts/1 | jq '.title'
# Filter arrays
curl https://jsonplaceholder.typicode.com/posts | jq '.[0:3]'
jq transforms unformatted JSON blobs into readable, colored, indented output. Use . to pretty-print everything, or specify paths like .title to extract individual fields.
Common Mistakes Beginners Make with cURL
Learning cURL is straightforward, but these pitfalls trip up newcomers:
1. Forgetting Quotes Around URLs with Special Characters
Wrong:
curl https://api.example.com/data?name=John&age=25
Right:
curl "https://api.example.com/data?name=John&age=25"
URLs containing &, ?, or spaces need quotes. Without them, your shell interprets these characters as separate commands or parameters.
2. Not Checking the Status Code
Receiving a response doesn't guarantee success. Always verify the status code:
curl -i https://example.com/api/nonexistent
A 404 error might be buried in the headers while the response body appears normal.
3. Mixing Up GET and POST
GET retrieves data, POST sends data. Using the wrong method causes errors:
# Wrong - trying to send data with GET
curl https://api.example.com/users -d '{"name":"John"}'
# Right - using POST to send data
curl -X POST https://api.example.com/users -d '{"name":"John"}'
4. Forgetting Content-Type Headers
When sending JSON data, specify the content type:
curl -X POST https://api.example.com/data \
-H "Content-Type: application/json" \
-d '{"key":"value"}'
Omitting this header leaves the server guessing your data format, often resulting in 400 Bad Request errors.
5. Not Following Redirects
Some URLs redirect to different locations. Add -L to follow them:
curl -L https://short.url/abc123
Without -L, cURL stops at the redirect instead of fetching the final destination.
Why cURL is Essential for Modern Programmers
Apply these basics to understand why cURL has become indispensable in daily development workflows.
Testing Backend on Cloud Servers
Picture this: you've deployed your backend API on a cloud server. SSH into the machine to verify everything works, but there's no browser installed. What now? Grab cURL and test instantly:
curl http://localhost:3000/api/health
No browser installation, no desktop environment needed. Direct testing from the command line saves time and resources.
Speed in Debugging
Debugging through browsers means managing tabs, waiting for page loads, clicking through UI elements. cURL delivers instant feedback:
# Instead of: open browser → log in → navigate → check response
curl -H "Authorization: Bearer token123" https://api.example.com/user/profile
One command, immediate response. Iterate through requests, modify parameters, and observe results without UI overhead.
GUI Tools Built on cURL
As you advance, you'll want features like request collections, organized tests, or visual interfaces. Tools like Postman and Insomnia are essentially GUI wrappers around cURL, providing friendlier interfaces while using the same underlying technology.
Think of cURL as learning manual transmission. Once you understand the mechanics, using automatic (GUI tools) becomes effortless, and you'll appreciate what happens under the hood.
The AI and LLM Era
Modern AI models and LLMs can't efficiently use browsers, but they excel with terminals and command-line tools like cURL.
Ask an AI assistant to test an API or fetch server data—it uses cURL behind the scenes. As AI-assisted development becomes standard, knowing cURL means speaking the same language as these tools. You can:
Request AI-generated cURL commands for complex API calls
Understand and modify AI-suggested commands
Automate workflows where AI agents interact with APIs through cURL
Conclusion
cURL transforms your terminal into a direct server communication channel. Whether testing APIs on remote servers, debugging efficiently, or collaborating with AI tools, cURL forms the foundation.
Start with simple GET requests, practice with free APIs, then explore POST requests and headers. Master cURL today, and every API test, debugging session, and automation script becomes faster throughout your programming career.
Comment Down with 200 OK! if you liked this