How to Make a GET Request with Curl

This article provides a straightforward guide on how to perform a simple HTTP GET request using curl, a popular command-line tool for transferring data over various network protocols. You will learn the basic command syntax, how to save the output to a file, how to view response headers, and how to handle redirects.

The Basic GET Request

By default, curl performs an HTTP GET request when you provide a URL. Open your terminal and run the following command:

curl https://api.github.com

This command sends a GET request to the specified URL and prints the raw response body directly to your terminal.

Saving the Output to a File

If the response is large or you want to save the data for later use, you can write the output to a file using the -o or -O options.

curl -o response.json https://api.github.com
curl -O https://example.com/index.html

Viewing Response Headers

To inspect the HTTP response headers (such as Content-Type, Status Code, and Server information) instead of the response body, use the -I (or --head) option:

curl -I https://example.com

If you want to view both the headers and the response body together, use the lowercase -i option:

curl -i https://example.com

Following Redirects

If the URL you are requesting redirects to another location, curl will not follow it by default. To force curl to follow HTTP redirects, add the -L (or --location) flag:

curl -L http://google.com