How to call REST API using CURL command in Linux.

Shubh
2 min readJul 14, 2023

--

In this blog we will learn how we can the data using curl command. If you are a developer/tester you must have used postman or swagger tool in windows to check whether API is working or not same we can do it by using curl command which we can execute in Linux. So lets begin

Benefits of CURL command:

  • Curl command is used to download or upload data to a server via supported protocols such as HTTP, FTP, IMAP, SFTP, TFTP, IMAP, POP3, SCP, etc.
  • Curl is portable and compatible with all popular operating systems.
  • Can be used in automation scripts.
  • Curl can provide detailed logs of what was sent and received and is very good at debugging and logging errors.
  • It is a remote utility, so it works without user interaction.

Steps to Execute:

STEP 1: Whenever we are calling any API we have to pass few parameters like header, token, data in body. So in curl command we need to use below tags to pass these values.

STEP 2: Call POST URL

curl -X POST URL

STEP 3: To send header in URL use below tag.

-H header_key: header_value

STEP 4: Send json data in URL.

-d json format data.

Also you can use some different format of file to upload the data rather than giving json data directly to the curl command.

E.g. -d file_upload.txt

Here file_upload.txt has data which you want to upload, it can be some json/text data.

STEP 5: We want to check the response in terminal.

-v

STEP 6: Use below command at the end of URL to save the response in some text file.

>file_name.txt

STEP 6: Now we have to add all these tags into one URL and pass it in command line interface.

It will look something like this:

curl -v -X POST https://ece-nprweub-da-eventhub-ns.servicebus.windows.net/ece-nprweub-da-test-automation-eventhub/messages -H “Content-Type: application/json” -H “Authorization: bearer jgfiwgewheueyiufeh7638613eiggaigwgdfdfjkdkjsdb” -d ’{“identifier”: “some value”, ”events”: “some value”, “use case”: “some value”}’ >curl_response.txt

If you like this post give a clap and follow me for other stuff.

Thanks & Regards,

Shubham Shukla

--

--