# Mastering cURL – A Developer's Best Friend for Testing APIs

Over the past few days, I've been exploring how the Internet works—from computer networks to DNS and DNS records.

Today, I learned about one of the most useful tools every developer should know: **cURL**.

At first, I thought cURL was just a command for opening websites from the terminal. But after learning more, I realized it's much more powerful than that.

Developers use cURL every day to test APIs, debug servers, send requests, download files, upload data, and much more.

Let's explore the basics.

* * *

## What is cURL?

**cURL (Client URL)** is a command-line tool used to transfer data between a client and a server using different network protocols.

It supports protocols like:

*   HTTP
    
*   HTTPS
    
*   FTP
    
*   SMTP
    
*   IMAP
    
*   LDAP
    
*   And many more.
    

In simple words:

> **cURL lets you communicate with servers directly from your terminal.**

* * *

# Your First cURL Command

Open your terminal and type:

```bash
curl https://example.com
```

The server responds with the HTML of the webpage.

No browser required.

* * *

# Fetch HTTP Headers

Sometimes we only want the response headers.

```bash
curl -I https://google.com
```

This returns information such as:

*   HTTP Status Code
    
*   Content-Type
    
*   Server
    
*   Date
    
*   Cache-Control
    

Very useful while debugging websites.

* * *

# Send a GET Request

Most APIs use GET requests to retrieve data.

Example:

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

The server responds with JSON data.

* * *

# Send a POST Request

To send data to a server:

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

This sends JSON data to the API.

* * *

# Add Custom Headers

Many APIs require authentication.

Headers can be added using:

```bash
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com
```

This is commonly used with REST APIs.

* * *

# Download a File

cURL can download files directly.

```bash
curl -O https://example.com/image.jpg
```

The file is saved in your current directory.

* * *

# Follow Redirects

Some websites redirect requests.

Use:

```bash
curl -L https://google.com
```

The `-L` flag tells cURL to automatically follow redirects.

* * *

# Verbose Mode

Want to see everything happening behind the scenes?

```bash
curl -v https://google.com
```

This displays:

*   DNS Lookup
    
*   TCP Connection
    
*   SSL Handshake
    
*   HTTP Request
    
*   HTTP Response
    

It's a great way to understand how clients communicate with servers.

* * *

# Why Every Developer Should Learn cURL

Whether you're a frontend developer, backend developer, or DevOps engineer, cURL is incredibly useful.

You can use it to:

*   Test REST APIs
    
*   Debug backend services
    
*   Verify server responses
    
*   Check HTTP headers
    
*   Download files
    
*   Authenticate API requests
    
*   Learn how HTTP works
    

It's one of those tools that seems simple but becomes invaluable in real-world development.

* * *

# My Biggest Takeaway

Before today, I thought browsers were the only way to interact with websites.

Now I understand that browsers are just one type of client.

Using cURL, I can communicate directly with servers, inspect responses, and test APIs without writing any code.

Learning cURL has also helped me understand HTTP requests more clearly, and I can already see how useful it will be when I start building REST APIs with Node.js.

Every day, another piece of the web development puzzle falls into place.
