Use curl when you need a fast answer from a URL without opening a browser. It is a command line tool for transferring data, and it has been around since 1998, which explains why it appears in so many docs, scripts, servers, and API guides [source: curl]. If you work with websites, APIs, webhooks, downloads, or server checks, curl is one of those tools that saves minutes every day.
TLDR: curl lets you send web requests straight from your terminal, such as curl https://example.com to fetch a page or curl -I https://example.com to inspect headers. A beginner testing a broken API can often check status, headers, and response data in under 60 seconds instead of clicking through a browser and guessing. Start with curl, -I, -o, -L, -X POST, and -H; those cover most beginner tasks.
What Is curl, Really?
curl is a terminal command that sends requests to URLs. Most beginners meet it while testing an API, downloading a file, or checking if a site is alive. It works on macOS, Linux, and modern Windows systems.
The nice part is that curl is direct. You ask a URL for something. You get the answer. No browser tabs. No waiting for page scripts. No mystery button hidden in a dashboard. Honestly, it feels like half of API debugging is just proving whether the server answered at all.
1. Fetch a Web Page
The simplest command is also the best place to start:
curl https://example.com
This prints the response body in your terminal. For a website, that usually means HTML. For an API, it may return JSON.
Use this when:
- You want to see what a URL returns.
- You are checking a basic endpoint.
- You want a quick response without opening a browser.
If the terminal fills with messy HTML, that is normal. curl is doing exactly what you asked.
2. Show Only Response Headers
Headers tell you useful things before you even read the page content. Use -I to fetch headers only:
curl -I https://example.com
You may see lines like:
HTTP/2 200
content-type: text/html
cache-control: max-age=604800
The most useful part is the status code. 200 means success. 301 or 302 means redirect. 404 means not found. 500 means the server had a bad day.
Beginner tip: When someone says, “The site is down,” run curl -I first. It quickly separates DNS, server, redirect, and permission problems.
3. Follow Redirects
By default, curl does not always follow redirects the way a browser does. That gets annoying fast. Use -L to follow them:
curl -L https://example.com
This matters when a URL sends you from http to https, or from one domain path to another. Without -L, you may only see a redirect message and wonder why nothing useful came back.
A common check is:
curl -IL https://example.com
This shows headers and follows redirects. It is great for checking where a short link, old page, or marketing URL actually ends up.
4. Download a File
To save a file with its original remote name, use -O:
curl -O https://example.com/file.zip
To choose your own file name, use -o:
curl -o report.zip https://example.com/file.zip
The lowercase -o is usually safer for beginners because you control the name. The uppercase -O uses the name from the URL.
Use this when:
- You need to download logs from a server.
- You want to save an API response to a file.
- You are scripting repeated downloads.
5. Save an API Response
APIs often return JSON. You can save that response like this:
curl -o users.json https://api.example.com/users
If you are debugging, this is much cleaner than copying text from a browser window. It also gives you a file to compare later.
If the response is large, expect the terminal to become unreadable. Saving it to a file avoids that mess.
6. Send a POST Request
GET requests ask for data. POST requests usually send data. Use -X POST to set the method:
curl -X POST https://api.example.com/users
That sends a POST request, but it does not send any useful data yet. To include JSON, add -d and a content type header:
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name":"Sam","role":"editor"}'
The -H option adds a header. The -d option sends data in the request body.
Small warning: JSON quotes break easily in terminals. One missing quote can waste five minutes for no good reason. On Windows PowerShell, quoting rules can also differ, which is deeply irritating when the same command worked fine elsewhere.
7. Add Request Headers
Many APIs need headers for tokens, content types, or versioning. Add headers with -H:
curl https://api.example.com/profile \
-H "Authorization: Bearer YOUR_TOKEN"
You can add more than one header:
curl https://api.example.com/profile \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Accept: application/json"
Never paste real tokens into shared chats, tickets, or screenshots. Treat them like passwords. If you already exposed one, rotate it.
8. Send Form Data
Not every endpoint uses JSON. Some expect form data. Use -d with simple key-value pairs:
curl -X POST https://example.com/login \
-d "email=user@example.com" \
-d "password=secret"
This sends data as a standard form request. It is handy for older systems, quick tests, and simple webhook checks.
9. See What curl Is Doing
When something fails, add -v for verbose output:
curl -v https://example.com
This shows connection details, request headers, response headers, TLS info, and more. It can look noisy, but it is useful noise.
Use verbose mode when:
- A request hangs.
- A server rejects your request.
- You suspect a TLS or redirect issue.
- An API works in one tool but not another.
If you only need the final status code, use this compact command:
curl -o /dev/null -s -w "%{http_code}\n" https://example.com
It hides the body, runs silently, and prints only the HTTP status code. That is perfect for scripts and uptime checks.
10. Set Timeouts
Some requests hang forever. Do not let them. Set a maximum time:
curl --max-time 10 https://example.com
This stops the request after 10 seconds. You can also only limit connection time:
curl --connect-timeout 5 https://example.com
These options are useful in scripts. Without them, one slow service can freeze the whole job.
11. Retry Failed Requests
Networks fail. Servers hiccup. Retry a request automatically like this:
curl --retry 3 https://example.com
This tries the request up to 3 more times for temporary failures. You can add a delay:
curl --retry 3 --retry-delay 2 https://example.com
That waits 2 seconds between attempts. For beginner scripts, this can make checks far more reliable.
12. Use Basic Authentication
Some endpoints use basic username and password auth:
curl -u username:password https://example.com/private
This is simple, but be careful. Commands can appear in shell history. A safer option is to type only the username:
curl -u username https://example.com/private
curl will ask for the password without showing it on screen.
A Practical Beginner Workflow
Here is a simple order that works well when testing an API:
- Check if the endpoint responds:
curl -I URL - Follow redirects if needed:
curl -IL URL - View the body:
curl URL - Add headers:
curl -H "Authorization: Bearer TOKEN" URL - Send test data:
curl -X POST -H "Content-Type: application/json" -d '{...}' URL - Debug with details:
curl -v URL
Expect to waste time on quoting, redirects, and missing headers at first. Everyone does. The fix is to build commands in small steps. Test the URL first. Add one option. Test again. Then add the next one.
Quick Cheat Sheet
curl URL— fetch a page or API response.curl -I URL— show response headers only.curl -L URL— follow redirects.curl -o file URL— save output to a named file.curl -O URL— save using the remote file name.curl -X POST URL— send a POST request.curl -H "Header: value" URL— add a request header.curl -d "key=value" URL— send data.curl -v URL— show debug details.curl --max-time 10 URL— stop after 10 seconds.curl --retry 3 URL— retry failed requests.
The best beginner curl habit is simple: start small, read the response, then add options one at a time. Once you know these commands, you can test websites, APIs, downloads, redirects, headers, and authentication from one terminal window.