curl for beginners: your first step into the world of HTTP requests
Published on 2025-09-08
Hello! If you’re even a little interested in the web, you’ve probably heard of curl.
It’s a powerful and versatile command-line tool for interacting with web servers. It is used to send and receive data over various protocols: HTTP, FTP, SFTP, as well as mail protocols.
This guide is your first step. We’ll focus on the basics to help you understand how curl works and how to use it for everyday tasks.
What is curl and why do you need it?
curl stands for Client URL. Think of it as your browser, but without the graphical interface. Instead of opening a web page, you can “ask” curl to make a request and show you the server’s response.
curl is often used for:
- testing APIs;
- downloading files;
- checking site availability;
- sending data to servers;
- interacting with mail servers.
Basic syntax
The simplest way to use curl is to specify a URL. By default, it performs a GET request, and the server’s response is displayed directly in the terminal:
curl https://example.com
This command downloads the HTML code of example.com’s main page and prints it in the console.
The most useful options for beginners
1. Verbose output (-v or --verbose)
To see request and response headers, use:
curl -v https://example.com
You will see:
- connection information;
- request headers (
>); - response headers (
<).
2. Saving a file (-O and -o)
# save file with original name
curl -O https://example.com/file.zip
# save under a different name
curl -o new_name.zip https://example.com/file.zip
3. Following redirects (-L or --location)
By default, curl does not follow redirects. To enable this:
curl -L http://example.com
Sending data: POST requests
GET requests retrieve data, while POST sends it.
To send data, use -d:
curl -X POST -d "name=mike&age=30" https://example.com/api/register
curl will automatically add the header Content-Type: application/x-www-form-urlencoded.
Working with mail protocols
curl supports SMTP, POP3, and IMAP. This is handy for testing or automation.
Sending an email (SMTP)
curl -v --url "smtp://smtp.example.com:587" \
--ssl-reqd \
--mail-from "sender@example.com" \
--mail-rcpt "recipient@example.com" \
--upload-file email.txt \
--user "username:password"
--ssl-reqd— requires TLS.--mail-from/--mail-rcpt— sender and recipient.--upload-file— the body of the email.
Reading emails (IMAP)
curl -v --url "imaps://imap.example.com" \
--user "username:password" \
-X "LIST \"\" \"INBOX\""
This requests the list of folders on the server.
Conclusion
curl is a tool that every developer and DevOps engineer should have in their toolkit.
We’ve covered the basics: GET and POST requests, file downloads, working with redirects, and even sending emails.
Start with these examples, and soon curl will become your reliable assistant in working with the web and networks.