Request basics

Make a GET request

Request one URL, see the response body, and separate curl output from the HTTP exchange.

10 minute lesson

~~~

With no method option, an HTTP URL normally produces a GET request: the plain “give me this resource” verb of the web. This is the command you will run more than any other, so it is worth understanding exactly what appears on your screen and why.

Request a small public page:

curl https://example.org/

The terminal should contain the returned HTML, starting with <!doctype html>. That text is the response body, exactly as the server sent it. curl adds nothing and interprets nothing — no rendering, no styling, just bytes.

Two output streams, one terminal

curl writes the response body to standard output and progress information to standard error. The progress meter is not part of that HTML, even though both may appear in one terminal window. You can prove the separation by sending each stream somewhere different:

curl https://example.org/ > page.html

The redirect captures only stdout, so page.html contains pure HTML while any progress output stays on screen. This separation is what makes curl composable: you can pipe the body into another tool without progress noise corrupting it.

When you want no progress output at all, add --silent:

curl --silent https://example.org/ | wc -c

The number printed is the body size in bytes, and nothing else leaked into the pipe.

Quote your URLs

Quote URLs containing ?, &, or shell wildcard characters. The shell processes those characters before curl sees them. An unquoted & puts curl in the background mid-URL, and an unquoted ? can match filenames in your current directory:

curl 'https://example.org/search?q=curl&page=2'

Single quotes hand the URL to curl untouched. Make this a habit now, before it costs you a confusing afternoon.

If you run a URL and get nothing back, check the exit status with echo $?. Zero means the transfer worked and the body was genuinely empty or went where you redirected it. Non-zero means the transfer itself failed, and the code tells you how — 6 is a DNS failure, 7 means the connection was refused.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →