# Getting Started with cURL

## What Is cURL? (Very Simple Explanation)

**cURL** is a command-line tool that lets you **send requests to a server and see the response**.

In simple words:

> **cURL helps your computer talk to another computer over the internet.**

When you use a browser:

* You type a URL
    
* The browser sends a request
    
* The server sends a response (HTML, JSON, etc.)
    

cURL does the **same thing**, but **without a browser**.

![https://53.fs1.hubspotusercontent-na1.net/hubfs/53/curl-command-1-20240924-8716216.webp](https://53.fs1.hubspotusercontent-na1.net/hubfs/53/curl-command-1-20240924-8716216.webp align="left")

![https://www.researchgate.net/publication/228662293/figure/fig1/AS%3A654412636749824%401533035539067/client-server-Request-and-Response.png](https://www.researchgate.net/publication/228662293/figure/fig1/AS%3A654412636749824%401533035539067/client-server-Request-and-Response.png align="left")

---

## Why Programmers Need cURL

Browsers hide many details.

Programmers need to:

* Test APIs
    
* Debug backend responses
    
* Send requests without a UI
    
* Automate HTTP calls
    
* Check headers and status codes
    

cURL is useful because:

* It works everywhere
    
* It is fast
    
* It shows raw request and response
    
* It does exactly what you ask (no hidden behavior)
    

---

## Making Your First Request Using cURL

Let’s start with the simplest request.

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

What happens here:

* cURL sends a **GET request**
    
* Server responds with data
    
* cURL prints the response in the terminal
    

This is similar to opening [`example.com`](http://example.com) in a browser, but you only see the **response body**.

---

## Understanding Request and Response

Every internet communication follows this pattern:

```plaintext
Request → Server → Response
```

![https://www.researchgate.net/publication/228703446/figure/fig1/AS%3A301961011318788%401449004523443/Flowchart-of-request-response-process.png](https://www.researchgate.net/publication/228703446/figure/fig1/AS%3A301961011318788%401449004523443/Flowchart-of-request-response-process.png align="left")

![https://loopback.io/pages/en/lb4/imgs/req-res-high-level.png](https://loopback.io/pages/en/lb4/imgs/req-res-high-level.png align="left")

### Request contains:

* URL
    
* Method (GET, POST, etc.)
    
* Headers
    
* Optional body (data)
    

### Response contains:

* Status code (200, 404, 500)
    
* Headers
    
* Body (HTML, JSON, text)
    

cURL lets you **see and control** these parts.

---

## Seeing Response Details (Status & Headers)

To see response headers:

```plaintext
curl -i https://example.com
```

* `-i` means “include headers”
    
* Useful for debugging API responses
    

You’ll see:

* HTTP status
    
* Content type
    
* Server info
    

---

## Using cURL to Talk to APIs

Most APIs return **JSON**, not HTML.

Example API request:

```plaintext
curl https://api.github.com
```

The response will look like JSON data.

This is how backend and frontend communicate internally.

---

### Sending Data (POST Request)

```plaintext
curl -X POST https://example.com/api \
  -H "Content-Type: application/json" \
  -d '{"name":"Aman","age":20}'
```

Explanation:

* `-X POST` → HTTP method
    
* `-H` → header
    
* `-d` → request body (data)
    

This is how:

* Forms submit data
    
* Login APIs work
    
* Backend receives input
    

![https://svitla.com/uploads/ckeditor/01_27.05.jpg](https://svitla.com/uploads/ckeditor/01_27.05.jpg align="left")

![https://kajabi-storefronts-production.kajabi-cdn.com/kajabi-storefronts-production/file-uploads/blogs/2147485434/images/315487-7af3-d17-c8af-0b4d8af188db_rest-api-model-diagram.png](https://kajabi-storefronts-production.kajabi-cdn.com/kajabi-storefronts-production/file-uploads/blogs/2147485434/images/315487-7af3-d17-c8af-0b4d8af188db_rest-api-model-diagram.png align="left")

---

## Common cURL Options (Beginner Useful)

| Option | Meaning |
| --- | --- |
| `-X` | HTTP method |
| `-H` | Add headers |
| `-d` | Send data |
| `-i` | Show headers |
| `-v` | Verbose (debug mode) |

You don’t need all of them at once.  
Use only what your request needs.

---

## Common Mistakes Beginners Make with cURL

### 1\. Forgetting Quotes

❌

```plaintext
-d {name:Aman}
```

✅

```plaintext
-d '{"name":"Aman"}'
```

---

### 2\. Wrong Content-Type

Sending JSON without header causes server errors.

Always add:

```plaintext
-H "Content-Type: application/json"
```

---

### 3\. Using GET When API Expects POST

If API expects data:

* GET won’t work
    
* Use POST, PUT, or PATCH
    

---

### 4\. Thinking cURL Is Only for Backend Devs

Frontend developers use cURL to:

* Test APIs before UI
    
* Debug CORS issues
    
* Verify backend responses
    

---

## How cURL Fits in Real Development

![https://svitla.com/uploads/ckeditor/01_27.05.jpg](https://svitla.com/uploads/ckeditor/01_27.05.jpg align="left")

![https://www.slideteam.net/media/catalog/product/cache/1280x720/f/r/framework_flowchart_of_api_test_automation_slide01.jpg](https://www.slideteam.net/media/catalog/product/cache/1280x720/f/r/framework_flowchart_of_api_test_automation_slide01.jpg align="left")

Typical flow:

* Backend builds API
    
* cURL tests API
    
* Frontend connects UI
    
* Bugs fixed faster
    

cURL acts as a **bridge** between frontend and backend.
