cURL 101 - Making HTTP Requests with Ease

cURL is a command-line tool that allows you to transfer data to or from a server using various protocols, including HTTP and HTTPS.

It is widely used for making HTTP requests from the command line, and it can also be used from within scripts to interact with APIs.

We'll learn how to make GET, POST, PUT, and DELETE requests with cURL, as well as how to set headers and send JSON data.

GET request

To make a GET request with cURL, you can use the following command:

curl http://example.com

POST request

To make a POST request with cURL, you can use the following command:

curl -X POST -d "data=value" http://example.com

In this example, we are sending the data data=value to the server.

PUT request

To make a PUT request with cURL, you can use the following command:

curl -X PUT -d "data=value" http://example.com

DELETE request

To make a DELETE request with cURL, you can use the following command:

curl -X DELETE http://example.com

With Headers

To set headers, use the -H option followed by the header name and value.

curl -H "Content-Type: application/json" http://example.com

JSON Body

You can set a JSON body in a cURL request by using the -d option followed by the JSON string.

curl -d '{"data": "value"}' http://example.com