# Beginner's Guide to Using cURL

**cURL (Client URL)** is a command-line tool that is preinstalled on most modern operating systems. It is used to **send requests to servers and receive responses** using different network protocols like **HTTP, HTTPS, FTP, and SMTP**.

### **Before starting with curl, we first need to understand what a client and a server are.**

A **client** is a computer or app (like a web browser) that sends requests to other computers. A **server** is the computer or system that receives those requests and responds to them. This setup is known as a **client-server architecture**.

Think of it like a **restaurant**: you, the person ordering food, are the **client**. The restaurant takes your order, prepares the food, and serves it to you, making the restaurant the **server**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768937597387/9578a65e-6f1d-4099-a500-3d1ee620b83a.png align="center")

**cURL** is a tool that lets us send requests to servers directly from the terminal. Sometimes, we don't have the full application ready, but we still need to test a specific **route** (the URL where the request is sent).

In these situations, **cURL** is the easiest and most useful way to test that route. It sends the request and displays the server's response directly in the terminal.

### **How to check if cURL is installed on your computer:**

To check if the cURL utility is installed on your operating system, you need to run a simple command.

```bash
curl -v
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768938774790/73303fcd-0e35-433e-8062-8e4e5eac980a.png align="center")

If you get a response like the one above, your computer already has the cURL utility. However, if you see an error, you may need to install it manually.

## **Now, how can you use cURL?**

Let’s perform your first curl request. In this case, we will send a GET request to a public API.

```bash
https://jsonplaceholder.typicode.com/users/
```

Open your terminal and type the following:

```bash
curl https://jsonplaceholder.typicode.com/users/
```

You will get some dummy users and their properties as the response directly in your terminal.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768938265423/df3d9d2b-3bf0-4e91-b27f-7808c1046beb.png align="center")

This is a simple example of how you can perform a **GET request**. A GET request is primarily used to retrieve existing data from a server, often from a database.

### **POST request with cURL**

A **POST request** is mainly used to **add new data or resources to a database** by sending information to a server. You can make a POST request using **cURL** like this:

```bash
curl -X POST https://yourapiurl.com \
  -H "Authorization: Bearer aoiueio2123olsudoas" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "your name"
  }'
```

### Explanation

* `-X POST` → Specifies the HTTP method as **POST**
    
* `-H "Authorization: ..."` → Sends the authorization token in the request header
    
* `-H "Content-Type: application/json"` → Tells the server that the request body is JSON
    
* `-d` → Contains the data that will be sent to the server
    

This request sends JSON data to the API, allowing the server to create a new resource in its database.

### **Final Thoughts**

You might wonder why we use **cURL** when tools like **Postman** are available. The reason is simple-both are used for API testing, but they have different uses. cURL runs directly from the terminal and is usually already installed on most operating systems, making it great for quick testing, automation, and scripting. It's especially helpful in remote environments like cloud servers, SSH sessions, or CI/CD pipelines where you can't use GUI tools like Postman. Postman, however, offers a graphical interface that's better for detailed API exploration, debugging, and teamwork during local development. In short, use cURL for fast, terminal-based testing and Postman for more detailed, visual API testing.
