# Getting Started with cURL

Let’s quickly go through with the topics that we are going to cover in this blog.

* What is cURL (in very simple terms)?
    
* Why programmers need cURL?
    
* Making your first request using cURL
    
* Understanding request and response
    
* Using cURL to talk to APIs
    
* Common mistakes beginners make with cURL
    

---

## What is cURL and why progrmmers need cURL?

Before understanding the cRUL let’s understand what is a server?

**Server are basically a dedicated computers that provide services on the behalf of client such as ordinary desktop computers or workstation**. So, it’s a centralised machine connected with multiple devices or client over the internet or LAN(Local Area Network). They connect with server for specific service. For example those services can be to retrieve a website, to access data or email and so on. **A server could be dedicated to handle one service at a time for example webserver(only for retrieveing the websites) , mailserver(to send and receive the mails) and more**. But it’s also possible to have a single server having all services included in it.

So, to talk with the server we as a client use the cURL, **cURL is a widely used open source software consists of command line tool (curl) and a development library (libcurl) for transferring the data with URL syntax.** It is mostly used by developer or administrator to automate tasks, testing APIs, upload and download files over a wide range of network protocols.

Server is a 24×7 running machine so to make that robust we can’t just use any ordinary desktop computers because they have some limitations which can’t handle more than a limit connections. **So, the server consists of a processor ie intel XEON different than that of a ordinary computer processor ie Intel i7,i5.**

**Xeon processor support a multi-processor environment to distibute the workload**(more than one porcessor are present) whereas ordinary computer support a single processor environment.

**Xeon processor support ECC RAM**(Error correcting code) which helps to maintain the robustness of a server by checking the processed data of RAM module, if there is an error it will correct it to prevent memory errors.

---

## Making your first request using cURL, request , response and APIs.

Before running these commands make sure your device has pre-installed the curl, check on internet how to install curl on your paricular operating system.

Below `—help` command will show you the list of commands that you can use with the curl.

```plaintext
curl --help
```

This command will output all the content of the mentioned website.

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

Below command will let you store the html code coming from the website into your local device with the file name `save.html`

```plaintext
curl -o save.html https://hashnode.com
```

It will show all the html content that you just pulled from the https://hashnode.com website.

```plaintext
cat save.html
```

`It will store the response output html into the index.html` file and you can see the file content using `cat` command.

```plaintext
curl -O https://hashnode.com/index.html
```

Let’s check below commands how redirecting checks are tested.

```plaintext
curl https://blog.meetabhinav.com

This command will extract all the content from my website.

Now let's check my catch all function that i set on my NameServe provider to redirect
https://meetabhinav.com to https://blog.meetabhinav.com


curl -L https://meetabhinav.com

Now this command will give me the content of the website blog.meetabhinav.com because its
gets redirected over there.
```

Now let’s know more interesting things, we can also check the response headers that are sent by webserver back to clients, the commands provided below.

```plaintext
curl -I https://hashnode.com
```

We can also see the TLS handshaking or client server communications execution using below command

```plaintext
curl -v https://hashnode.com
```

By the way GET is the default function assigned to curl command and if you want to use POST you can use the `-d` or `—data` command for example curl https://dummy\_data//path -d “x = something & y = something” and this will POST into the server.

Search online on internet free api dummy data and select the method and copy paste the path and run the curl command to check the functionality.

---

## Common mistakes beginners make with cURL

* Skipping Documentation & Proper Research
    
* Failure to Check Return Codes
    
* Disabling TLS Certificate Checks
    
* Ignoring Thread Safety Rules
    

And many more, google or search by yourself to know more.

---

## Conclusion

You might get uncomfortable using cURL but don’t worry you will get it somedays. Do online research and try to learn the command and also impliment on your device to see the working of commands to know better.
