# Getting Started with cURL

In your web development journey, you will have to test APIs many times, whether they are REST APIs or GraphQL APIs. Though tools like Postman are available for API testing, did you know that you can test APIs directly from your terminal? Yes!

cURL or Client URL is that tool that allows to do that. It is a command line tool used to transfer data to or from a server using URLS. It supports different protocols like HTTP/HTTPS, FTP, SMTP, SFTP, SCP, default one is HTTP.  
Basic syntax: `curl [options] [url]`

```bash
curl -I http://example.com
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1771097889133/ee817452-83a0-4cc9-8099-b78edb8ca0aa.png align="center")

Here is the general **response** we will get though curl.  
This ‘200’ is called as **status code**  
For different types of responses different status code is used  
for example:  
\-200/201 for success,  
\-404 for network error and  
\-500 for server error.  
  
**Content-type** : text/html tells us that the returned data is of type html.  
This are some common parts of an API response.

cURL gives different types of commands such as Get, Post, delete etc. Lets see some of its features.  
We'll use a [**https://jsonplaceholder.typicode.com**](https://jsonplaceholder.typicode.com) API, this is a free public test api that will help us to learn and understand cURL better.

**1.) Get request**

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

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1771096993955/afef7410-71b6-4f24-9270-550ba57abf44.png align="center")

This is the output of all posts listed out, if we want only one we can set ID = 1

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

Here is single post output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1771097054196/109f0e2c-2933-4009-bd69-ff1f4458e355.png align="center")

**2.) POST method**

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

Here we used some flags, lets understand them  
\-X used to tell http method other than get → ex: -X POST or -X DELETE

\-H used to add file header ( meta data of data)  
\-d used to give data to post  
Here is the output:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1771097182697/2f33d803-40b0-4e22-a9ad-1cf08139e6a0.png align="center")

It might felts overwhelming but if once you go through the commands and try them on your own, the fog will start to clear.  
Here is a fun curl command as a gift for reading till now :

```bash
curl parrot.live
```

Hope you your answers and enjoyed the cURL.
