Skip to main content

Command Palette

Search for a command to run...

Beginner's Guide to Using cURL: Simple Steps to Start Now

Updated
3 min read
Beginner's Guide to Using cURL: Simple Steps to Start Now

Before starting with cURL let’s first understand about the Server. So what exaclty is Server , it is basically a device or computer whose job is to recieve requests , process them and send back response

  • For example : it is same like when we opens the web page at that time also browser sends the request to the server and server sends back HTML, CSS , JS , images and all the data of that webpage and then we are able to access the website

What is cURL ?

cURL is basically a tool that let you talks to server directly using your terminal mean you dont have to go to the browser to send the request to server.

like very simple we simply have to tell cURL where we have to send the request and what kind of request it is and boom it shows you all the things that server replies back.

Why programmers need cURL

As a developer , specially when we are dealing with the backend side then we generaly don’t want to go to browser again and again or we always dont want a UI , frontend . What we want is to test some APIs , Debug server responses and check if a server is alive or not. that why when we use cURL , we can directly talk to server, test our APIs and what not that’s why programmers need cURL.

Our First cuRL request

let’s start with the demo how can we send the curl reques

curl https://chaicode.com

Like here you can see we have made a cURL request to the server of chaicode.com by using cURL and as a response we got the HTML page, and cURL printed whole response into our terminal that is how we can make request to the server, thing to notice it cURL don’t render the page or haven’t applied any CSS it only showd us raw data returned by the server.

Understanding request and response

  1. Request → Sent’s by the client , which can be through browser or using cURL

    like in this example i have sent the request through my browser to ther server of chaicode.com,so this is how a request can be sent.

  2. Response → Sent by the server , which is Data (HTML, CSS, JSON etc

    like we have sent the request to chaicode.com and as a response you can see we have got the landing page of the website.

Understanding HTTP Methods : GET and POST

  1. GET request → GET itself is defining we are getting something , mean by using this method we are Asking for the data from the server , used while fetching data

    • NOTE : when we are sending request through cURL by default it is GET request.

Example :

    curl https://api.myapp.com/users
  1. POST request → it is used when we want to send data to the server , while using it we have to specify that we are using POST method like this

    Example :

     curl -X POST https://api.myapp.com/users
    

Using cURL to talk to APIs

For understanding the API request using cURL we are going to send the request to the github api and let see what type of response we are getting.

So, we have used curl https://github.com/users/Shubh-ujala and you can see we have got the JSON data which contains almost every information about my github account, this is how we can send the API request using cURL.

Common Mistakes with cURL

  1. Expecting a webpage UI →As a beginner we can expect some UI as a response but what we get a raw data as a response.

  2. Thinking cURL replaces browser → It doesn’t , it just tests communication , not user experience.

  3. Using too many flags too early → this leads to memoriztion , not understanding.