Skip to main content

Command Palette

Search for a command to run...

What is cURL and How to Use It Effectively

Using cURL: A Step-by-Step Instruction

Updated
5 min read
What is cURL and How to Use It Effectively
S

Frontend Developer 💻 | Fueled by curiosity and Tea ☕ | Always learning and exploring new technologies.

Before diving into cURL, let’s first understand the basics.

What Is a Server and Why Do We Talk to It?

When you open a website or use an app, your device is not doing all the work.
It asks another computer on the internet to send data. That computer is called a server.

Examples:

  • When you open Google → your browser talks to Google’s server

  • When your app shows products → it talks to an API server

  • When you submit a form → data is sent to a server

So every time something loads from the internet, this is happening:

Client → sends request → Server → sends response

Where Does cURL Fit In?

Usually, the client is:

  • A browser (Chrome, Firefox)

  • A mobile app

  • Postman

But sometimes developers want to talk to the server directly, without any UI.

That is where cURL comes in.

cURL is a tool that lets you send requests to a server from the terminal and see the raw response.

Think of it as:

A browser for developers, inside the terminal.

You type a command, the request is sent, and the server sends back data.

cURL

What Is cURL

cURL is a command-line tool used to send and receive data using URLs.

It can:

  • Request web pages

  • Talk to APIs

  • Send data to servers

  • Download files

But instead of clicking buttons, you type commands.

Why we need cURL

Developers use cURL because:

  • You can test if a server is working

  • You can test APIs without writing frontend code

  • You can debug request and response behavior

  • It works almost everywhere (Linux, macOS, Windows)

It is often the first tool used to check backend systems.

First Request Using cURL

Let’s start with the simplest possible example.

curl https://jsonplaceholder.typicode.com/todos/1

This command:

  • Sends a request to the server

  • The server sends back data

  • cURL prints that data in the terminal

You will see something like:

This is exactly what a browser would receive, but now you are seeing it directly.

Understanding Request and Response

Every network call has two parts:

Request (What You Send)

It contains:

  • The URL

  • The request method (GET, POST, etc.)

  • Optional data and headers

Example: “Give me todo item number 1.”

Response (What You Get Back)

It contains:

  • Status code (success or error)

  • Data returned by the server

Example:

  • 200 OK → success

  • 404 Not Found → resource does not exist

And then the actual data (HTML, JSON, file, etc.).

cURL shows you the response body by default, which is usually what you care about first.

Using cURL to Talk to server

Most APIs work using HTTP requests.

GET — Asking for Data

GET is used when you want to fetch something.

curl https://jsonplaceholder.typicode.com/posts/1

Meaning: “Give me the post with ID 1.”

POST — Sending Data

POST is used when you want to send new data to the server.

curl -X POST https://jsonplaceholder.typicode.com/posts \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Hello",
    "body": "Learning cURL",
    "userId": 1
  }'

Here:

  • -X POST tells cURL to use POST

  • -H sends a header

  • -d sends the data

Meaning: “Create a new post using this data.”

The server may responds with the created object.

Seeing More Details with Verbose Mode

Sometimes you want to see what is happening behind the scenes.

Use:

curl -v https://api.github.com/search/users?q=satpalsinhrana

Verbose mode shows:

  • Request headers sent

  • Status code returned

  • Response headers

It will look something like:

This helps when:

  • Requests fail

  • APIs return unexpected errors

But for normal usage, you usually do not need -v.

Downloading a File Instead of Printing It

By default, cURL prints everything in the terminal.

To save the response into a file:

curl -o google.html https://www.google.com

Now the data is written into google.html instead of the screen.

Following Redirecting Request

Sometimes you type google.com but the server moves you to www.google.com. By default, cURL stops at the redirect. Use -L (Location) to tell cURL to follow the trail to the final destination.

Example of Normal Request

curl google.com

Example of Following Redirecting Request

curl -L google.com

cURL Options

cURL supports many options, but you do not need most of them at the start.

For beginners, these are enough:

FlagMeaningSimple Terms
-vVerboseShow me Very much detail
-oOutputWrite Output to a file
-LLocationFollow the new Location (Redirects)
-XRequest Methodexecute this method (GET/POST)
-dDataSend this Data
-HHeaderAdd this Header

Fun Time

Try this in your terminal:

curl wttr.in

Or, for a custom ASCII-style response, check out my server:

curl https://ascii.satpal.cloud/

Github Repo 🔗

If you can use cURL comfortably, you already understand how the web really works behind the UI.

“Understanding client and server is the first step to mastering the web.”

— Unknown

To uncover more secrets about the invisible infrastructure powering your daily life, be sure to read my full series on The Internet.

Check out the full series: The Internet by Satpalsinh Rana

The Internet

Part 7 of 10

From typing a URL to a fully loaded webpage, data travels through a global network of fiber cables, routers, and servers. This series covers core concepts every CS engineer should know to understand how the modern web works.

Up next

DNS Records

Everything You Should Know About DNS Records