DEV Community

Cover image for Rabit Hole of the Curl command
Bhupesh Chandra Joshi
Bhupesh Chandra Joshi

Posted on • Edited on

Rabit Hole of the Curl command

History of cURL?

What is cURL?
Curl is a cli(command line interface) tool that is a functional component to send data between client and server.

When you want to communicate with your kitchen staff dirrectly the curl command appears in your mind or you are a postman lover.In this article ,we will break down the curl command step by step.

What is curl? Curl is a command line tool that helps you communicate with the songbird(server) you Love, just a approach to send a request to server and getting back the response(Just like chocolate).

The curl is just like a Train that contains your order Cart items, a post card for your request reponse cycle. Curl,the open source software that uses the http/ https protocol to the transfer the data.

Why programmers need cURL?
Why this curl, because it doesn't require the graphical interface you can send data from client to server ,just using the command line terminal and available on windows,linux and mac os.

To answer this question? I will ask a counter question, in Hindi-
hum kehte hai question pe question, who is good programmer?
A person who writes the quality code, follows the standards and also take care for making your present system light wieght ,so , The question has answer itself, curl makes us strong, we know and it makes us tention free that our api is returning the correct response ,we know with help of curl's response.

Do you want to check the health of your application, how server is working behind the scene type the command.

Why programmers need cURL?

cURL stands for client url , it is a portable ,secure and saves the time when we need the quick response for api testing, every developer wants that his rest api/ graph ql api performs well, for quick note:it is a mandatory skill for a developer.

What is the server?
Server is a special type of computer that is designed to listen your request 24/7. Thid the formula to check the health of your application.

Let's fetch your webpage using curl and curl is pre installed on every os, so you can use it,it's your choice.
curl https://wellness-ai-topaz.vercel.app/

So, we have performed the get request operation with my project and it's a way you can perform the get request from terminal just like vim. Get request is dialing a phone number to your friend.

What is the request?

Request is just like a prayer to god and we have done the get request here. Get for the obtaining the data, for example when we search on google and we get the response(result) from the google server.

Response , we understand the response,this is the status code sent by the server. So we have done the get request for health check of our application here.

curl -I url

It will present the health of your website. for example we have taken example of chatgpt. -I,-X is the flag, the flug provides the type of request or the method type,which we are performing or requesting to a server.

curl -I https://chatgpt.com

curl -X POST http://localhost:3000/api/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "Test@123",
"fullName": "Test User"
}'

The purpose of curl : It allow us to make request to a website/ api or server from the terminal.

-X flag describes the which method you will use. POST means you are creating the resource and -H flag indicates the header of your request.

-d indicates the payload the actual data of your project.

Test User Login:

curl -X POST http://localhost:3000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "Test@123"
}'

Common mistakes beginners make with cURL
When developers are fiddling with cURL, there are the common list of mistakes which developers will find affectionable.

1-Some mistakes are c / c++ specific.
2- Skipping the documentation: It's a common problem for every developer, there are some rumors that developers got affected that they are not content writer, so company should hire the technical writer for this purpose.
3-User write the code with libcurl and they forget to check the return code.
4-The Users got problems while using the curl, either they are developers or testers, testing with the curl. Setting up the required get/post method, they experience issue, the correct syntax and the longer syntax sometimes they feel harder to remember.
5-Licenses mistakes are common for some developers who are excessively using ai and they don't check which lisense perticular project utilize.

Trick to check from terminal / command prompt from windows
steps
1-Open the terminal
2-Type sudo -i and enter your password, you will login as root user in your terminal
3- Type curl -v google.com

You will see the connected message ,

Problem:if you are connected to internet in the terminal, if you are not connected to internet, you will find the could not resolve the host google message.

Solution: contect to internet

Implementation: Try these fun tricks, you need not to type a url ,is internet is working or not.

Top comments (0)