curl is one of the most essential tools in every developer's toolkit. Whether you're debugging APIs, downloading files, testing server endpoints, or automating HTTP requests, curl is your go-to command-line utility. This guide covers 50+ practical curl examples organized by use case so you can quickly find what you need.
curl (short for "Client URL") is a command-line tool and library for transferring data with URLs. It supports HTTP, HTTPS, FTP, SFTP, SCP, SMTP, and dozens of other protocols. Originally released in 1998 by Daniel Stenberg, curl is pre-installed on virtually every Linux, macOS, and Windows 10+ system.
The fundamental syntax of curl is straightforward:
curl [options] [URL]
By default, curl performs an HTTP GET request and prints the response body to stdout.
curl https://api.example.com/users
curl "https://api.example.com/users?page=1&limit=10"
curl -H "Authorization: Bearer YOUR_TOKEN" \
-H "Accept: application/json" \
https://api.example.com/users
curl -v https://api.example.com/users
curl -I https://api.example.com/users
curl -i https://api.example.com/users
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
curl -X POST https://api.example.com/login \
-d "username=alice&password=secret"
curl -X POST https://api.example.com/upload \
-F "file=@/path/to/document.pdf" \
-F "description=Quarterly report"
-F for multipart/form-data uploads (common in file uploads), and -d for application/x-www-form-urlencoded or raw data.curl -X PUT https://api.example.com/users/42 \
-H "Content-Type: application/json" \
-d '{"name": "Alice Updated", "email": "alice@new.com"}'
curl -X PATCH https://api.example.com/users/42 \
-H "Content-Type: application/json" \
-d '{"email": "alice@new.com"}'
curl -X DELETE https://api.example.com/users/42 \
-H "Authorization: Bearer YOUR_TOKEN"
curl -u username:password https://api.example.com/protected
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1..." \
https://api.example.com/me
For debugging JWT tokens, use our free JWT Decoder tool to inspect token payloads.
curl -X POST https://auth.example.com/token \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_ID" \
-d "client_secret=YOUR_SECRET"
curl -H "X-API-Key: your-api-key-here" \
https://api.example.com/data
By default, curl does not follow redirects. Use -L to follow them:
curl -L https://example.com/redirect-endpoint
curl -L --max-redirs 3 https://example.com
curl -O https://example.com/file.zip
curl -o myfile.zip https://example.com/file.zip
curl -C - -O https://example.com/large-file.iso
curl -# -O https://example.com/file.zip
curl -s -O https://example.com/file.zip
-sS (silent + show errors) in scripts so you suppress progress output but still see error messages.curl -X PUT -T /path/to/file.txt \
https://storage.example.com/uploads/file.txt
curl -X POST https://api.example.com/upload \
-F "file1=@photo.jpg" \
-F "file2=@document.pdf" \
-F "metadata={\"tags\":[\"report\"]};type=application/json"
# Set a header
curl -H "Content-Type: application/json" https://api.example.com
# Set multiple headers
curl -H "Accept: application/json" \
-H "X-Request-ID: abc123" \
https://api.example.com
# Remove a default header
curl -H "User-Agent:" https://api.example.com
# Send a custom User-Agent
curl -A "MyApp/1.0" https://api.example.com
curl -c cookies.txt https://example.com/login
curl -b cookies.txt https://example.com/dashboard
curl -b "session_id=abc123" https://example.com
curl -k https://self-signed.example.com/api
curl --cacert /path/to/ca.crt https://example.com
curl --cert client.crt --key client.key \
https://example.com/api
-k (insecure) in production. It disables all SSL certificate verification and exposes you to man-in-the-middle attacks.curl --connect-timeout 10 https://api.example.com
curl --max-time 30 https://api.example.com
curl --rate 10/m https://api.example.com/data
# HTTP proxy
curl -x http://proxy.example.com:8080 https://api.example.com
# SOCKS5 proxy
curl --socks5 127.0.0.1:1080 https://api.example.com
# Proxy with authentication
curl -x http://user:pass@proxy.example.com:8080 https://api.example.com
curl -v https://api.example.com
curl -s -D - https://api.example.com -o /dev/null
curl -w "time_total: %{time_total}s\n" -s -o /dev/null https://api.example.com
curl -s -w "HTTP Code: %{http_code}\nTotal Time: %{time_total}s\nSize: %{size_download} bytes\n" \
-o /dev/null https://api.example.com
curl -s https://api.example.com/users | python3 -m json.tool
For formatting JSON online, try our JSON Formatter & Beautifier.
| Option | Description | Example |
|---|---|---|
-X | HTTP method | -X POST |
-H | Request header | -H "Content-Type: application/json" |
-d | POST data | -d '{"key":"value"}' |
-F | Multipart form upload | -F "file=@photo.jpg" |
-o | Write output to file | -o output.html |
-O | Save with remote filename | -O |
-L | Follow redirects | -L |
-u | Basic auth | -u user:pass |
-b | Send cookies | -b "name=value" |
-c | Save cookies | -c cookies.txt |
-s | Silent mode | -s |
-v | Verbose output | -v |
-k | Skip SSL verification | -k |
-i | Include response headers | -i |
-I | HEAD request (headers only) | -I |
-A | User-Agent string | -A "MyBot/1.0" |
-C - | Resume download | -C - -O url |
-w | Format output with variables | -w "%{http_code}" |
--data-binary | Send binary data | --data-binary @file.bin |
--compressed | Request compressed response | --compressed |
While curl is the king of CLI HTTP, for interactive API testing, tools like Postman and HTTP status code references can be helpful. Here's when to use what:
-H "Content-Type: application/json": Many APIs reject requests without the correct Content-Type.-L for redirects: APIs using OAuth flows often redirect, and curl won't follow by default.-k in production: Disabling SSL verification is dangerous.& in URLs: Shell interprets & as a background operator — always quote URLs with &.Here's a practical example of using curl in a script to check website health and extract response data:
#!/bin/bash
# health_check.sh — Monitor API endpoints
ENDPOINTS=(
"https://api.example.com/health"
"https://api.example.com/users"
)
for url in "${ENDPOINTS[@]}"; do
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$url")
TIME=$(curl -s -o /dev/null -w "%{time_total}" --max-time 10 "$url")
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "✅ $url — HTTP $HTTP_CODE (${TIME}s)"
else
echo "❌ $url — HTTP $HTTP_CODE (${TIME}s)"
fi
done
curl is an incredibly powerful and versatile tool that every developer should master. Whether you're building REST APIs, debugging authentication flows, automating deployments, or simply downloading files, the examples in this cheat sheet cover the most common scenarios. Bookmark this page and keep it handy — you'll reach for these curl commands daily.
For more developer tools and guides, explore the Hedpy Blog or check out our free online developer tools.
nbsp; AI API接口 →