DEV Community

Cover image for How to use CURL
Israel-Lopes
Israel-Lopes

Posted on • Updated on

How to use CURL

CURL is a command line tool that allows you to transfer data to or from any URL. It is commonly used for testing APIs and making HTTP requests.

Installation

Before using CURL you need to make sure it is installed on your machine. On Linux, you can verify that cURL is installed by running the curl --version command in the terminal. If URL is installed, you will see its version. If not, you can install it using your operating system's package manager. For example, on Ubuntu, you can use the sudo apt-get install curl command to install cURL.

Basic usage

cURL is used in the terminal or command prompt to make HTTP requests. Below are some basic examples of how to use cURL:

Make a GET request

To make a GET request using cURL, simply use the curl command followed by the URL of the request. For example, to make a GET request for the URL https://www.example.com, you could use the following command:

curl https://www.example.com

This will send a GET request to the specified URL and display the contents of the response in the terminal output.

Make a POST request

To make a POST request using cURL, simply add the -X POST option to the curl command. Also, you can pass the data you want to send in the request using the -d option. For example, to send the data name=John&age=30 in a POST request to the URL https://www.example.com, you could use the following command:

curl -X POST -d 'name=John&age=30' https://www.example.com

Make a request with custom headers

You can also add custom headers to your requests using cURL. To do so, simply use the -H option followed by the desired header and value. For example, to add the header Authorization: Bearer <TOKEN> to your request

curl --color https://www.example.com
Enter fullscreen mode Exit fullscreen mode

If the request is successful (i.e. the response status code is in the 2xx range), the output will be colored green. If the request is unsuccessful (i.e. the response status code is in the 4xx or 5xx range), the output will be colored red.

You can also customize the colors used by cURL by using the --style option followed by the desired style. For example, to use the solarized color style, you can use the following command:

curl --color --style solarized https://www.example.com
Enter fullscreen mode Exit fullscreen mode

This will use the colors specified by the solarized style for the output.

I hope this helps! Let me know if you have any other

Texto alternativo da imagem)

Top comments (0)