Share your love
Make a GET Request With cURL
In this guide, we want to teach you to How To Make a GET Request With cURL. As you must know cURL is a Linux command line utility that is used to transfer data over the Internet. You can easily use the cURL command to request data and receive your desired information. Here you will learn to make a get request by using the curl command.
How To Make a GET Request With cURL?
To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. Then, follow the steps below to see how you can make a get request.
The curl command line tool is installed on the Linux distros by default.
Making an HTTP Get Request with cURL
You can request data from a web server by using the HTTP Get Request. HTTP GET requests cannot send data to the server in the body of a GET message or change the server’s state. But you can still pass data to the server in URL parameters.
The format to make a get request is like the following:
curl -X GET <URL>
You can replace the URL with your target server and make a get request for it. For example:
curl -X https://google.com
The -X GET option specifies that the HTTP method is GET. When the command runs, curl sends a GET request to the server specified in the URL and waits for the server’s response.
If the server responds with a successful status code, the curl displays the response body in the terminal.
Or you can use the following syntax instead:
curl https://google.com
This command will show you the same results as the above command.
Getting only HTTP Headers with cURL
At this point, you can only request a for only HTTP headers instead of getting the body of the request. To do this, you can use the -I option in the curl command. For example:
curl -I https://google.com
Making a JSON Request with cURL
You can receive your data in the format of JSON. To do this, you can use the -H “Accept: application/json” option in the curl command. For example:
curl https://google.com -H "Accept: application/json"
You can easily use the cURL command to make your get requests from a server.
For more information about the curl command and how to download files, you can visit this guide on How To Use the curl command in Linux.
Conclusion
At this point, you have learned to Make an HTTP GET Request, Get HTTP Headers, and JSON request With cURL command. Need any help or suggestions? Please comment for us.
Also, you may like these articles: