cURL command line tutorials with examples

This tutorial shows the basics of cURL command-line tools cURL Installation on Linux/Unix and windows.

CURL is a command-line tool used to send data between two machines. data can be transferred via HTTP or FTP protocols of any URL/file.

cURL command is used to test API during the development phase.

This tool is available in Windows, Linux, Unix, and Mac operating systems.

Understanding cURL command Usage

  • Retrieving Content from URL
  • Testing REST API
  • Upload/download files
  • get Response and Location headers of any remote URL or websites

cURL command install and configure on windows

For developers, This is the basic and important command to test REST API in a console.

Please download the CURL executable cURL executable🔗 to install/configure on windows and extract the downloaded zip folder to the filesystem as below

Install Curl command line tool on windows

If you want to access the curl command globally, Please set up the environment variable by adding curl.exe to a PATH environment variable.

CURL Command-line tools setup in Linux/Unix

we can set up curl command tools easily using the apt-get command. Root permission is required to install curl command tools.

sudo apt install curl

Basic Usage of cURL syntax

this command has minimum tow parameters one is to use the double hyphen as part of the options and the other is a URL or a file.

Usage: curl [options...] {url}

Various options of cURL tools

We will go through some basic options of the command line.

OptionsDescription
-UProxy URL user details login and password
-Asend request headers parameters as part of a request to the server
-mcommand full documentation about this command
-OMultiple files/URLs support
-LLocation information
-Vretrieve full request and response header information of a URL
-Iretrieve full response header information
-xproxy support
-TUpload file support
-XRequest method type support
-HModify request header
-drequest body data

The below section will see curl examples with tutorials and CURL command line tools options.

Retrieve the content of the URL/file

It is the basic command to retrieve the cloudhadoop site content. By default, the content will be out to the console.

curl cloudhadoop.com

Multiple Files/URLs download content

To retrieve multiple file content, use the -o option.

curl -O file1 file2 URL1`

Use option -I to retrieve the response headers,

C:\curl\src>curl -I http://www.cloudhadoop.com
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Expires: Fri, 13 Jul 2018 09:33:14 GMT
Date: Fri, 13 Jul 2018 09:33:14 GMT
Cache-Control: private, max-age=0
Last-Modified: Fri, 13 Jul 2018 07:23:27 GMT
ETag: "d2546e8a-0752-47f1-b30c-0e4a5535b852"
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Length: 0
Server: GSE

How to get request response headers with content using CURL

cURL command with -v retrieve verbose of any url. Please see the below screenshot.

cURL command Verbose windows

cURL command usage with HTTP methods GET/POST/PUT/Delete

curl without any options to request a URL is treated as a GET request. to send different request method types, use the -X option.

It is the command-line version of the postman client for Testing web service API.

curl -H "Content-Type: application/json" --d '{"id":"1"}' http://localhost:3000/get/customer
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1}' http://localhost/api/customers

This is my understanding of curl command tools in Linux/windows. Please share your comments if you have any questions