The Client URL -> cURL
What is cURL
cURL stands for client URL. A cURL is referred to as a non-interactive web browser for the Linux terminal. This command line tool let you transfer the data to and from a server. It provides the facility to talk with server by giving specific address in a URL form and data you want to send. It support several different protocol, Including http and https and compatible with almost every different platforms. These all features make it ideal for testing communication.
Why cURL, what’s the need of it.
It can be used to quickly download, upload, send data file through the command line.
And also, it can be used to script automated updates.
Used for testing remote API.
If the service is unresponsive. Then you can use the cURL command line to test it.
First request on cURL
Installing cURL on Ubuntu : On terminal type command
sudo apt install curl
Requesting a web page from the command line :
curl https://www.google.com
The web server response will be displayed directly into the terminal.
Request and Response
HTTP is a hypertext transfer protocol which is communication protocol used to communicate between client (browser) to server (computer which stores website data or API).
HTTP is a stateless protocol means that if doesn’t remember what has been requested 5 sec ago.
The Core Analogy : We can think it like, In a restaurant,
The customer ( Client ) → Checking the menu
Order ( Request ) → Ordering food to the waiter
Kitchen ( Server ) → Kitchen accepts order and cook if ingredients are available
- Ordered Food ( Response ) → Waiter comes back with food or tells you if they are out of ingredients.
Structure : The HTTP request and response almost have same structure.

Head : This is a metadata, information that what message tells like who is sending, type of content and how long it is.
Body : This is a payload, the actual content like HTML page, JSON data of an API or an image.
HTTP Request : Client telling the server that what action to perform on what resource. And it has three key components.
HTTP Methods : Defines the action
GET : For reading like loading web page
POST : For creating like submit a signup form.
PUT/PATCH : For updating like change your profile picture.
DELETE : For removing or deleting content.
URL (Destination) : Address of the resource.
Request Header :
Authorization : providing ID badge / Password
Accept : Acceptance of file format like JSON. ( “/“ means accept all file formats)
User-Agent : Using which version of client like I am using chrome on an iPhone.
HTTP Response : Reply given by server, also having 3 key components.
Status Code : Client outcomes represent by 3 digit number, such as
2xx : Success - means it worked. Example 200 means OK.
3xx : Redirection - redirecting the information that this file is not here anymore, find there. Example, 301 means moved permanently.
4xx : Client Error. Example, 404 not found , 401 unauthorized.
5xx : Server Error. Example,500 internal server error.
Response Headers : Receiving metadata from the server.
Content-type : The type of data server sent, img, JSON, txt.
Set-Cookie : Saving token for next time.
Cache-Control : That how long browser can store the requested files.
Body : This will represent the payload which was requested for. If the request got successful then it will show web page or data otherwise it will represent the error detail description.
Using cURL to talk to APIs
There are some request which can be made such as :
GET request : It is the easiest part of the request. syntax :
curl [URL]
You can also get more information from it with -v (shortcut of —verbose) adding before URL.

You can extract exact id (id=3) data also :
curl https://api.restful-api.dev/objects?id=3
POST request : Uploading some data into server.
Create a object first →
{ "name": "Apple MacBook Pro 16", "data": { "year": 2019, "price": 2049.99, "CPU model": "Intel Core i9", "Hard disk size": "1 TB", "color": "silver" } }then run the command → In the response it will create an object in the server.
curl -X POSThttps://api.restful-api.dev/objects-H 'Content-Type: application/json' -d '{"name":"Apple MacBook Pro 16","data":{"year":2019,"price":2049.99,"CPU model":"Intel Core i9","Hard disk size":"1 TB","color":"silver"}}'PUT request : To update all fields or replace existing record, therefore we have to provide its
idCommand →
curl -X PUThttps://api.restful-api.dev/objects/:id-H 'Content-Type: application/json' -d '{"name":"Apple MacBook Pro 16","data":{"year":2022,"price":2399.99,"CPU model":"M1","Hard disk size":"1 TB","color":"space grey"}}'DELETE request : Remove our resource with DELETE. No payload required, just again our resource id.
curl -X DELETEhttps://api.restful-api.dev/objects/:id
Your object has been deleted.
Common mistakes using cURL
| Issue | Flag/Symptom | Solution |
| URL cutoff | URL has & or ? | Wrap URL in double quotes "". |
| API error | Server says "Unsupported Media Type" | Add -H "Content-Type: application/json". |
| Windows error | "Bad Request" or syntax error | Use double quotes " and escape inner quotes \". |
| Unknown error | No output / vague error | Add -v to see the debug info. |