Open Forem

Cover image for cURL — The Bridge Between You and Servers
Kunal
Kunal

Posted on

cURL — The Bridge Between You and Servers

In this blog, we’ll cover:

  • What is a server and why we need to talk to it ?
  • 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

Server

Think of a server your friend

You request some money from your friend
If your friend has good mood and has money , you get a response "Sure"
Otherwise says "NO"

A server works the same .

👉 A server is a hardware or software that process your request send over a network and in return server will give response to you .

If you want to know more about what the network is i strongly recommend you the read this blog 👇

But why we need to talk to a Server

A server is important becouse :

  • You get the data

  • Send data

  • Update data

  • Remove data

You dont able to upload a photo on a Social media if you dont want to talk with a server


cURL : Client URL

cURL short for "Client URL" is a command line tool (ping , ipconfig) used to transfer and download data to a specific server by specifying the location ( in the form of URL ) .

It requires only command line interface (CLI) such as powershell, cmd and Warp to run .

Why they are widely used by programmers

They are widely used by programmers as :

  • They perform a quick HTTP request to a server .

  • It can perform GET , POST and other HTTP request .

  • It is mostly used by backend developers for testing the API .3


Practical examples of cURL

To use cURL you have a command line interface ( CLI ) in your device such
powershell , cmd and Warp

Here are some few cURL commands thar every developer should know .

Fetching a website

This command will return the HTML of a website

curl google.com
Enter fullscreen mode Exit fullscreen mode

curl

Sending GET requests

The most common form of HTTP request is GET request . It is used to when we want to retrieve data from the server

curl https://dummyjson.com/products
Enter fullscreen mode Exit fullscreen mode

get

Check the content part you get all the list of products

Sending POST requests

Another frequent used HTTP is POST , which is used to send or update the data of server

curl.exe -X POST https://httpbin.org/anything
Enter fullscreen mode Exit fullscreen mode

vurl


Common mistakes beginners make with cURL

  • Writing the URL without quotes

  • Ignoring the response status code

  • Sending invalid JSON format

  • Forgetting the cURL commands


Thanks for reading ! if enjoyed this blog , you can read more on this 👇

Top comments (0)