# Getting Started with cURL

Have you ever wondered that how does a browser opens a website in our computer ? How does this complex process occurs within milliseconds and we as a user gets our desired output. For understanding this first we have to gain some knowledge about severs.

## How Server works ?

Server is a powerful computer that has 3 main job to do which is

> to store data
> 
> to process requests
> 
> to send response to client

Server is a computer which works 24×7 hours , which is always connected to internet and which handles thousands or sometimes millions of clients.

while using our computer we talk to server many times and we didn’t even notice that thing. when and how we talk to server

> * opening a website
>     
> * login into app
>     
> * watch a video
>     
> * send a message
>     
> * save something
>     

Our computer cannot do everything by itself. Consider our device as a client and server as a remote powerful computer.

How do Clients talk to servers ?

The clients talk to server by using some protocols HTTP/HTTPS , Request and responses and APIs. Every request will be looks like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1769183531589/d651159b-025f-47a9-8cdf-67602f13ea43.png align="center")

Now the big question arise is how does this requests goes to the server ? do developers send all requests manually ? So the answer is NO , developer doesn’t send requests manually . This is where **cURL** comes in.

## <mark>What is cURL ?</mark>

cURL means client URL . It is a command line tool that is used to

> * fetch data from URL
>     
> * send request to server
>     
> * test APIs
>     
> * to debug backend services
>     

## <mark>Why we need cURL ?</mark>

cURL is a way to talk with servers without browser. Because browser hides details such as IP,NS servers, etc , browsers can automates all things and are not good for testing APIs. So cURL is used we need it because:

> * fetch data from URL
>     
> * check server response
>     
> * sends GET,POST,PUT,DELETE requests
>     
> * inspect header ,status codes , errors
>     

## Sending Request using cURL:

The simplest possible way to fetch a website is

> `curl http://chaicode.com`

it sends an HTTP GET request , downloads the HTML on webpage and prints it out in our terminal.

## <mark>Understanding Request and Response:</mark>

After using that command `curl http://chaicode.com` cURL generates a request. A request has basically 4 parts;

> 1. method =&gt; GET
>     
> 2. path =&gt; /
>     
> 3. headers =&gt; database
>     
> 4. body =&gt; to get response for GET
>     

servers receives the request and gives a HTTP Response in the body. Response also has 3 parts :

> 1. status code
>     
> 2. Headers
>     
> 3. Body
>     

## <mark>How cURL talks to APIs:</mark>

API is just a server endpoint that listens for HTTP requests , expects specific methods, body and gives response. cURL is a client that sends those requests exactly as API expects.

## Common mistakes beginners make with cURL:

> 1. forgetting the HTTP method
>     
> 2. not setting content type
>     
> 3. wrong quotes (in JSON)
>     
> 4. forgetting Authentication Header
>     
> 5. not checking status code
>     
> 6. ignoring error messages
>     
> 7. forgetting -v while debugging
>     
> 8. expecting cURL to behave like a browser
>     
> 9. copy pasting without understanding
>     

---

***<mark>Thank you for reading . Have a happy learning journey. I hope this article added some value for your given precious time.</mark>***
