What is Header-Case?
Header-Case is a capitalization style specifically designed for HTTP headers where each word is capitalized and separated by hyphens. It's similar to Train-Case but follows the established conventions of web protocols and REST APIs.
Examples:
Content-Type
Authorization
Cache-Control
User-Agent
X-Api-KeyWhen to Use Header-Case
- HTTP Headers: Request and response headers
- REST APIs: API header names
- Custom Headers: X-prefixed custom headers
- Web Protocols: Standard web communication headers
- Email Headers: MIME headers and metadata
- API Documentation: Documenting header requirements
Common HTTP Headers
Request Headers:
Accept: application/json
Authorization: Bearer token123
Content-Type: application/json
User-Agent: Mozilla/5.0
Accept-Language: en-USResponse Headers:
Content-Type: application/json
Cache-Control: no-cache
Set-Cookie: session=abc123
Access-Control-Allow-Origin: *
X-Rate-Limit: 100Custom Headers:
X-Api-Key: your-key-here
X-Request-Id: abc-123-def
X-Custom-Header: value
X-Forwarded-For: 192.168.1.1Examples in Code
JavaScript Fetch:
fetch('https://api.example.com/data', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer token',
'X-Api-Key': 'your-key'
}
});cURL Command:
curl -X GET https://api.example.com \
-H "Content-Type: application/json" \
-H "Authorization: Bearer token" \
-H "X-Custom-Header: value"Header-Case Conventions
Standard Headers
Follow established names: Content-Type, Authorization, Cache-Control, User-Agent.
Custom Headers
Prefix with X- for custom headers: X-Api-Key, X-Request-Id, X-Custom-Data.
Case Sensitivity
HTTP headers are case-insensitive, but Header-Case is the standard convention.
Best Practices
- ✓ Use for all HTTP headers
- ✓ Follow standard header names
- ✓ Prefix custom headers with X-
- ✓ Be consistent across your API
- ✗ Don't use spaces (use hyphens)
- ✗ Avoid abbreviations in custom headers
- ⚠️ Remember: HTTP headers are case-insensitive
- ⚠️ Use established conventions for common headers