Getting Started with cURL
What Is a Server?
A server is something that answers requests made by users.
Whenever we want data like a webpage, user details, or search results we send a request to a server, and the server sends back a response.
We talk to servers because:
We want data
We want to submit data
We want some action to be performed (like login or form submission)
How Do Requests Normally Work?
In daily life, your browser talks to servers for you.
For example:
You open a website
Click a button
Submit a form
Behind the scenes:
Your computer sends a request to the server
The server processes it
The server sends back a response
You never see this process because the browser handles everything.
Why Do Developers Need cURL?
Backend developers and programmers often want to:
Test APIs
Debug backend code
Check server responses
Send requests without a browser or app
This is where cURL comes into the picture.
What Is cURL?
cURL is a command-line tool used to send requests to server and receive responses from servers.

In simple words:
cURL allows us to talk directly to a server from the terminal.
Why Programmers Use cURL?
Programmers use cURL because:
It lets them communicate directly with servers and APIs
No browser or UI is needed
It’s fast, lightweight, and powerful
Perfect for testing and debugging APIs
Making Your First Request Using cURL
Step 1: Open the Terminal
macOS / Linux → Terminal
Windows → Command Prompt or PowerShell
Step 2: Type the following command
curl https://www.google.com
Press Enter. This is your first cURL request.
What Just Happened?
Your computer sent a request to Google’s server
The server sent back the webpage data
cURL printed the response directly in the terminal
Understanding Server Responses
Whenever a server responds, it sends two things:
1. Status Code
Tells us whether the request succeeded or failed.
Common status codes:
200 OK → Everything worked correctly
301 Moved → Page has moved (redirect)
404 Not Found → Page doesn’t exist
500 Internal Server Error → Server error
2. Data
The actual content returned by the server.
The data format depends on the API or request:
HTML
JSON
Plain text
Files (images, PDFs, etc.)
Using cURL to Talk to APIs
An API (Application Programming Interface) is a server that:
Expects a request
Returns data in response (usually JSON)
Example: GitHub API
Run this command:
curl https://api.github.com/users/octocat
What Happens?
You send a request to GitHub’s API
The server returns user data in JSON format
Example response:
{
"login": "octocat",
"id": 583231,
"public_repos": 8,
"followers": 3930
}
GET Requests Using cURL
When you run:
curl https://api.github.com/users/octocat
It is a GET request by default.
GET Request:
- Used to fetch data from a server
POST Requests Using cURL
A POST request is used to send data to the server.
Example:
curl -X POST https://api.example.com/products
PUT : Update Existing Data
PUT is used to update an existing resource completely.
Simple meaning:
Replace the old data with new data.
Example:
Imagine a user profile:
Old data:
{
"name": "Ankit",
"age": 21
}
PUT request:
curl -X PUT -d "name=Ankit Kumar&age=22" https://api.example.com/users/1
New data:
{
"name": "Ankit Kumar",
"age": 22
}
PUT replaces the entire resource.
PATCH: Partially Update Data
PATCH is used to update only specific fields.
Simple meaning:
Change only what is needed.
Example:
You only want to update the age.
curl -X PATCH -d "age=23" https://api.example.com/users/1
Result:
{
"name": "Ankit Kumar",
"age": 23
}
PATCH does not touch other fields.
DELETE: Remove Data
DELETE is used to remove data from the server.
Simple meaning:
Delete a resource completely.
Example:
curl -X DELETE https://api.example.com/users/1
Result:
- User with ID
1is removed from the server
Common Mistakes Beginners Make with cURL
Expecting formatted output: cURL shows raw data, not pretty UI
Forgetting https:// in the URL
Forgetting -X for POST, PUT, DELETE requests
Sending data without -d
Example mistake:
curl -X POST https://api.example.com/products
Correct way (with data):
curl -X POST -d "name=phone" https://api.example.com/products