Request basics
Make a GET request
Request one URL, see the response body, and separate curl output from the HTTP exchange.
Give curl an HTTP URL and nothing else, and it sends a GET request. GET is the plain “give me this resource” verb of the web. You’ll run this command more than any other, so let’s look closely at what shows up on screen and why.
Request a small public page:
curl https://example.org/
The terminal fills with HTML, starting with <!doctype html>. That’s 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 the progress meter to standard error. They look mixed together in your terminal, but they’re separate streams. You can prove it by redirecting one:
curl https://example.org/ > page.html
The > captures only stdout, so page.html contains pure HTML. The progress meter stays on screen.
This separation is what makes curl composable. You can pipe the body into another tool, and progress noise won’t corrupt 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. Nothing else leaked into the pipe.
Quote your URLs
Quote every URL that contains ?, &, or wildcard characters. The shell processes those characters before curl sees them. An unquoted & puts curl in the background halfway through the URL. 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. I quote every URL, even the ones that don’t need it, so I never have to think about it.
When you get nothing back
If a command prints nothing, check the exit status:
echo $?
Zero means the transfer worked. The body was empty, or it went where you redirected it. Non-zero means the transfer itself failed, and the number tells you how. 6 means curl could not resolve the hostname. 7 means it could not connect to the server.
Try this with a typo in the hostname, like curl https://exampel.org/. You’ll see curl: (6) Could not resolve host: exampel.org and echo $? prints 6. Learn to read that number. Scripts depend on it, and so will the rest of this course.
Lesson completed