# What is cURL and How to Use It Effectively

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.

```bash
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:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769433531728/791d889b-a6de-466c-a4e3-07338d6771ba.png align="left")

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**.

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

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769434913310/45c14e21-dfb0-4c7b-b4f6-af7ddd9af79d.png align="center")

### POST — Sending Data

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

```bash
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.”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769434969460/1b5b4fc3-11e0-40df-bca8-f4866c3c8279.png align="center")

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:

```bash
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:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769433951999/8197e2e2-e903-49a2-88dd-050293ad7558.png align="center")

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:

```bash
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**

```bash
curl google.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769434195162/d7fdc8a5-b4e3-4c4e-827d-f2f7420ff79f.png align="center")

**Example of Following Redirecting Request**

```bash
curl -L google.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769434275522/60cdb6ad-98ac-44a1-9e35-c33998b7d5ab.png align="center")

## cURL Options

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

For beginners, these are enough:

| **Flag** | **Meaning** | **Simple Terms** |
| --- | --- | --- |
| `-v` | **Verbose** | Show me Very much detail |
| `-o` | **Output** | Write Output to a file |
| `-L` | **Location** | Follow the new Location (Redirects) |
| `-X` | **Request Method** | execute this method (GET/POST) |
| `-d` | **Data** | Send this Data |
| `-H` | **Header** | Add this Header |

## Fun Time

Try this in your terminal:

```bash
curl wttr.in
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769441618952/9ec7a684-9776-43ae-b96d-50e9bb00ee14.png align="center")

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

```bash
curl https://ascii.satpal.cloud/
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769441759841/63fe5ff3-504b-42d2-b936-7bddd826018c.png align="center")

[Github Repo 🔗](https://github.com/Satpal777/curl-utility)

  
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**](https://blogs.satpal.cloud/series/internet)
