Skip to main content

Command Palette

Search for a command to run...

Getting Started with cURL

Updated
5 min read
A

I’m Ashwin Gudepu, a web development learner currently part of the Chai Code cohort. I’m blind, so accessibility is not an afterthought for me. I write about coding, tools, and lessons from building usable web apps.

cURL Explained Simply: Talking to Servers from the Terminal

Before we start: what is a server and why do we talk to it?

Let’s start with a simple idea.

Whenever you use the internet, you are talking to a server.

  • You open a website

  • You use an app

  • You log in somewhere

  • You fetch some data

In all these cases, your device sends a request to a server, and the server sends back a response.

Think of it like this:

  • You ask a question

  • The server answers

Usually, a browser sits in the middle and does this quietly for you. It hides many details so everything feels smooth.

But what if you want to:

  • See what the server actually sends

  • Test an API without a browser

  • Understand what’s really happening

That’s where cURL is useful.


1. What is cURL (in very simple terms)

cURL is a tool that lets you send requests to a server from the terminal.

You type a command.
cURL sends a message to the server.
The server replies.
cURL prints the reply exactly as it is.

No design.
No formatting.
No hiding.

Just raw output.

Important thing to remember early:

cURL is not a browser.

It does not:

  • Render web pages

  • Run JavaScript

  • Make things look nice

It only talks and listens.


2. Why programmers need cURL

Browsers are made for normal users.
Programmers need something different.

Browsers:

  • Automatically follow redirects

  • Hide many errors

  • Run JavaScript in the background

  • Change how responses look

This is great for users, but confusing when you are learning.

Programmers use cURL because:

  • It shows the real server response

  • It is perfect for testing APIs

  • It works without building a frontend

  • It behaves the same on every system

One important point:

cURL is mostly used for APIs,
but you can send a request to any URL, and it will show whatever the server sends back.


3. Making your first request using cURL

Let’s start with the simplest possible command.

curl https://example.com

What this means in plain language:

  • “Send a request to this server”

  • “Give me the default response”

What happens next:

  1. cURL sends a request

  2. The server processes it

  3. The server sends back a response

  4. cURL prints the response in the terminal

You might see:

  • HTML code

  • Text

  • JSON

  • Or a message saying the page moved somewhere else

All of this is normal.

For example:

curl https://google.com

You may see a message like “301 Moved”.
That means the server is saying:

“This page has moved to another address.”

Browsers automatically follow this.
cURL does not unless you ask it to.

This is not an error.
It’s just the server being honest.


4. Understanding request and response

The request

A request usually includes:

  • What you want to do (GET or POST)

  • The address (URL)

  • Sometimes extra data

When you run:

curl https://example.com

You are making a GET request.

GET simply means:

“Please give me data.”

The response

The server replies with:

  • A status code

  • Some data

Common status codes you’ll see:

  • 200 → success

  • 301 → moved to another place

  • 404 → not found

  • 401 → not allowed

By default, cURL shows only the response body, not the explanation.

That’s why output can look confusing at first.


5. Using cURL to talk to APIs

This is where cURL feels the most comfortable.

APIs are built for programs, not for browsers.
They expect requests and return clean data, usually in JSON format.

curl https://api.github.com

Instead of HTML, you get structured JSON.

That tells you:

  • You are talking to an API

  • The server expects tools like cURL

  • No browser tricks are involved

At the beginner level, you only need to understand two request types:

  • GET → get data

  • POST → send data

That’s enough for now.


A small but important note about -I and -o

-I : check headers only

curl -I https://example.com

This shows:

  • Status code

  • Content type

  • Other response details

It’s useful when you want to understand what kind of response you’ll get, without downloading everything.

-o : save output to a file

By default, cURL prints output to the terminal.

If the response is a file (like a PDF or image), the terminal will look broken.

curl -o file.pdf https://example.com/file.pdf

This tells cURL:

“Don’t print it. Save it.”


6. Common mistakes beginners make with cURL

Thinking cURL behaves like a browser

It doesn’t. Sites that depend on JavaScript or heavy security may return raw HTML.

Getting scared by messy output

Messy output usually means the server responded honestly.

Printing files to the terminal

Binary files are not meant for terminals. Use -o to save them.

Expecting pretty formatting

cURL shows raw data. Formatting comes later.

Testing random websites instead of APIs

cURL works best with APIs. Websites are built for humans.


Where cURL fits in backend development

cURL sits between your code and the server.

Backend developers use it to:

  • Test endpoints

  • Debug responses

  • Understand server behavior

  • Check things before writing code


Final takeaway

Think of it like this:

  • A browser tries to help you

  • cURL tells you the truth

cURL shows what the server actually sent, without hiding anything.

If you understand cURL at this level:

  • APIs feel less scary

  • Backend concepts make more sense

  • Errors become learning tools

This is a strong and complete starting point for beginners.