# Getting Started with cURL

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768846003266/51726be2-ebe9-4c4c-914b-819c941662f3.png align="center")

To learn about `curl` , let’s know a little about the `server` first.

So, a server lets us / `client` access the data, resources giving us proper management, compute and ensures efficient working for apps and users.

`Data` - yes, that’s what curl exactly helps us do.

Let’s see what `linux` tells us about it—

curl is a tool for transferring data from or to a server using URLs. It supports these protocols: FILE, FTP, HTTP, HTTPS, IMAP, SMTP, WS and WSS etc.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769184043575/2f58c2cb-676c-4791-95c5-9b518e50b8a4.png align="center")

* **options** — allowing us to add flags (-o, -i etc.) to modify output.
    
* **URL** — we can give the url to fetch / send data.
    

**Request using curl** —

```plaintext
curl https://some-website.com
```

Curl fetches from the URL and prints the content in the terminal:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769189315909/b4458e0c-dfea-4193-8cc3-e098c9925c55.png align="center")

Save output in a file

```plaintext
curl example.com -o output.txt
```

**Testing APIs** —

Let’s try making a `POST` request using `curl`.

When testing APIs we need to send data, use different HTTP methods. `curl` flags can help us with that:

* `-X` → choose http method (here, POST)
    
* `-H` → specify type of data (JSON)
    
* `-d` → to append our JSON string
    
* `-v` → verbose output
    

`/` for moving to the next line

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

so, a post request will look something like this using curl and we’ll get the response inside our terminal.

**Response** —

```plaintext
{
  "title": "foo",
  "body": "bar",
  "userId": 1,
  "id": 101
}
```

The response returned here is only data oriented, if we use the `-v` flag, curl prints each and every step that happens while making the request.

**common mistakes**—

* even an extra `” “` space can ruin the request, cli is sensitive
    
* since we’re using cli, confusion can increase — no pretty print/write and
    
* using `\` to format data / multi line commands can be tough
    
* missing flags or headers (like `-H Content-Type`) can lead to request rejection.
