DEV Community

Rajat Yadav
Rajat Yadav

Posted on

Getting Started with cURL

Before jumping into tools like cURL, we need to understand something more important:

Who are we even talking to?

That “someone” is called a server.


What Is a Server? (In Very Simple Words)

A server is just a computer that gives something when you ask for it.

It can:

  • send you a website
  • give you data
  • store your files
  • save your login info

When you open Instagram, submit a form, or fetch API data you are talking to a server.

You (your browser, your app, your terminal) are called the client.

So the basic idea is:

Client  →  Server  →  Response
Enter fullscreen mode Exit fullscreen mode

You ask.
Server processes.
Server replies.

That’s it.


Does a Server Look Special?

Not really.

A server is also a computer, just like yours.
It has:

  • CPU
  • Memory
  • Storage
  • Operating System (Ubuntu, Windows Server, etc.)

The only difference?

It is always running and always ready to respond to requests.


Types of Servers

There are different kinds of servers depending on what they provide.

1. Web Server

Delivers websites (HTML, CSS, JavaScript, images).

Example flow:

Browser → Web Server → HTML page
Enter fullscreen mode Exit fullscreen mode

2. File Server

Stores and manages files.

Client → File Server → File Download
Enter fullscreen mode Exit fullscreen mode

3. Mail Server

Handles sending and receiving emails.

Email App → Mail Server → Inbox
Enter fullscreen mode Exit fullscreen mode

4. Database Server

Stores structured data (like users, products, orders).

Backend App → Database Server → Data
Enter fullscreen mode Exit fullscreen mode

Now that we understand servers…

Let’s talk about how we can speak to them without a browser.


What is cURL? (Very Simple Explanation)

cURL is a command-line tool that lets you send requests to a server directly from your terminal.

Instead of clicking buttons in a browser,
you type a command.

That’s it.

cURL stands for Client URL.

Meaning:

  • You are the client
  • You send something to a URL
  • You get a response back

How cURL Communicates

Here’s what happens when you use cURL:

Terminal (You)
      ↓
cURL builds HTTP request
      ↓
Server receives request
      ↓
Server sends response
      ↓
cURL prints response in terminal
Enter fullscreen mode Exit fullscreen mode

No UI.
No fancy design.
Just raw communication.


Your First cURL Command

The simplest possible example:

curl https://example.com
Enter fullscreen mode Exit fullscreen mode

What just happened?

  1. cURL sent a GET request to the server.
  2. The server processed it.
  3. The server sent back a response.
  4. cURL printed the response (HTML) in your terminal.

You just fetched a webpage without opening a browser.

Feels small… but it’s powerful.


What Exactly Is a Request and Response?

Every HTTP communication has two parts:

Request  →  Response
Enter fullscreen mode Exit fullscreen mode

The Request (What You Send)

A request usually contains:

  • URL (where you’re sending it)
  • Method (GET or POST)
  • Headers (extra info)
  • Body (data, sometimes)

The Response (What Server Sends Back)

A response has three main parts:

1. Status Code

Tells you what happened.

  • 200 → Success
  • 404 → Not Found
  • 500 → Server Error

2. Headers

Extra information like content type, date, etc.


3. Body

The actual data (HTML, JSON, text, etc.)


If you want to see everything (status + headers + body), use:

curl -i https://example.com
Enter fullscreen mode Exit fullscreen mode

You’ll see something like:

HTTP/2 200
content-type: text/html
Enter fullscreen mode Exit fullscreen mode

Then the HTML.

200 means it worked.


GET vs POST (Only These Two for Now)

Don’t overload yourself with too many methods.

Just understand these two.


GET → “Give me data.”

Used to fetch or read something.

Default in cURL.

Example:

curl https://api.example.com/users
Enter fullscreen mode Exit fullscreen mode

This means:

“Hey server, send me users.”


POST → “Here is data. Do something with it.”

Used when sending data to the server.

Example:

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'
Enter fullscreen mode Exit fullscreen mode

What this does:

  • -X POST → use POST method
  • -H → sending extra information
  • -d → sending actual data

Don’t worry about remembering everything now. Just understand the idea.


Using cURL to Talk to APIs

APIs are just URLs that send back data (usually JSON).

Example:

curl https://jsonplaceholder.typicode.com/posts/1
Enter fullscreen mode Exit fullscreen mode

You’ll get something like:

{
  "userId": 1,
  "id": 1,
  "title": "...",
  "body": "..."
}
Enter fullscreen mode Exit fullscreen mode

That’s an API response.

You just interacted with a backend system directly.


Browser vs cURL (Conceptual Difference)

Both send HTTP requests.

But:

Browser:
Request → Server → Response → Render UI
Enter fullscreen mode Exit fullscreen mode
cURL:
Request → Server → Raw Response in Terminal
Enter fullscreen mode Exit fullscreen mode

Browser shows design.
cURL shows truth.

That’s why backend developers love it.


Common Mistakes Beginners Make

Let me save you some frustration 😅

1. Forgetting quotes

If URL has spaces or special characters:

curl "https://example.com?name=John Doe"
Enter fullscreen mode Exit fullscreen mode

2. Wrong Content-Type

If sending JSON, always add:

-H "Content-Type: application/json"
Enter fullscreen mode Exit fullscreen mode

3. Typos in URL

http vs https
Missing slash
Wrong domain

Happens more than you think.


4. Ignoring Status Code

Always check:

HTTP/2 200
Enter fullscreen mode Exit fullscreen mode

Use -i if needed.


Where cURL Fits in Backend Development

If you’re building backend APIs:

You build endpoint
      ↓
You test with cURL
      ↓
You verify response
      ↓
Frontend connects later
Enter fullscreen mode Exit fullscreen mode

It’s fast.
No need for frontend.
No need for Postman (at least initially).

Also used in:

  • Automation scripts
  • Cron jobs
  • Health checks
  • Debugging production issues

Final Thought

cURL is not complicated.

It just looks scary because it’s raw.

But once you understand this flow:

Client → Request → Server → Response
Enter fullscreen mode Exit fullscreen mode

Everything becomes logical.

Start small.
Use simple GET requests.
Slowly add headers and POST.

Confidence first. Depth later.

Top comments (0)