When you need to check if a webpage or resource exists without downloading its full content, cURL HEAD requests are your go-to tool. With a simple command like curl -I, you can send a HEAD request to a URL and retrieve only the headers—think status codes, content type, and file size—without the body. This approach is fast, bandwidth-efficient, and perfect for tasks like confirming resource availability or scouting API endpoints.
Want an even more streamlined API experience? ApyHub provides a powerful suite of API tools that simplify testing and automation.
01What is cURL HEAD Requests?
A cURL HEAD request is an HTTP request that retrieves only the headers of a response without the actual body content. It is useful for checking metadata, such as content type, length, or server information, without downloading the entire resource.
02Why Use HEAD Requests for API Testing?
HEAD requests are an essential part of API testing and debugging. They allow you to:
- Check for resource availability
- Validate response headers
- Optimize network efficiency
03How to Use a cURL HEAD Request
To use a cURL HEAD request, you can follow these simple steps:
1. Basic cURL HEAD Request
This will only fetch the response headers of a URL, not the body. The -I or --head option specifies the HEAD method.
Syntax:
curl -I <URL>Example:
curl -I https://www.example.comExample Output:
HTTP/2 200
date: Fri, 14 Mar 2025 12:34:56 GMT
content-type: text/html; charset=UTF-8
content-length: 12345
server: ApacheThe output includes status code, date, content type, content length, etc.
2. Specifying Headers with the Request
You can include custom headers in the HEAD request by using the -H flag. For example, to check if an API endpoint supports a specific Accept header:
curl -I -H "Accept: application/json" https://api.example.com/endpoint3. Using HEAD Request to Check Response Time
Measure the response time by redirecting the output to /dev/null and using the -w flag to print the time:
curl -o /dev/null -s -w "%{time_total}\n" -I https://www.example.comThis will show the total time it took for the server to respond.
4. Additional Options
-
Follow redirects: If the server responds with a redirect (HTTP 3xx), use
-L:· shcurl -I -L https://www.example.com -
Show verbose output: Use
-vfor detailed request/response info:· shcurl -I -v https://www.example.com
5. Using HEAD Request for API Testing
Check headers before making a full GET request:
curl -I https://api.example.com/dataThis returns headers like content-type, status, or cache-control.
04Real-World Applications and Scenarios
cURL HEAD requests solve real problems. Here’s how developers use them:
1. Bulk URL Validation
Check multiple links programmatically:
for url in $(cat urls.txt); do
status=$(curl -I -s -o /dev/null -w "%{http_code}" "$url")
echo "$url: $status"
doneStatus Codes:
200 = Good, 404 = Gone, 301 = Redirected.
2. Pre-Download Size Checks
Check file size before downloading:
curl -I https://example.com/downloads/app.zipLook for Content-Length in the response headers.
3. Freshness Tracking
Check when a resource was last modified:
curl -I https://example.com/news/articleLook for Last-Modified in headers.
4. API Scouting
Test API availability:
curl -I https://api.weather.com/v1/forecastA 200 OK means it’s live; 403 Forbidden indicates access issues.
05Advanced Techniques and Integrations
1. Automate Site Monitoring
Create a script to monitor URLs:
#!/bin/bash
urls=("https://example.com" "https://api.example.com")
for url in "${urls[@]}"; do
status=$(curl -I -s -o /dev/null -w "%{http_code}" "$url")
if [ "$status" -ne 200 ]; then
echo "Alert: $url is down (Status: $status)"
fi
doneRun via cron for continuous monitoring.
2. Hook Into Monitoring Tools
Integrate with Prometheus for lightweight checks:
- job_name: 'site_health'
http:
method: HEAD
static_configs:
- targets: ['https://example.com']3. Inspect Redirects
Check redirect headers without following them:
curl -I https://example.comLook for 301 status and Location headers.
4. Parse with Tools
Extract custom headers using jq:
curl -I https://api.example.com/data | jq -R 'split("\r\n") | .[] | select(startswith("X-"))'This filters headers like X-Rate-Limit.
06Best Practices for Using cURL HEAD Requests
- Validate URLs before executing commands.
- Use
-vfor debugging, but disable it in production scripts. - Avoid
-k(insecure SSL) in sensitive environments. - Monitor API rate limits for bulk requests.
- Automate with Bash/Python scripts.
07Conclusion
cURL HEAD requests are a lean, efficient way to probe web resources and APIs. They deliver critical insights—like status codes and metadata—without downloading full content. From bulk URL checks to API monitoring, they’re a must-have tool for developers.
08Frequently Asked Questions (FAQ)
Can I use cURL HEAD requests with authentication?
Yes! Use -u username:password for basic auth or -H "Authorization: Bearer <token>" for tokens.
Can I limit the request timeout?
Yes, use --max-time <seconds>:
curl -I --max-time 5 https://example.comHow to use cURL behind a proxy?
Specify the proxy with -x:
curl -I -x http://proxyserver:port https://example.comHow to check API rate limits?
Extract headers like X-Rate-Limit-Remaining:
curl -I https://api.example.com | grep "X-Rate-Limit"How to save headers to a file?
Use -o:
curl -I https://example.com -o headers.txtWhere to find ApyHub’s API tools?


