Headers API 🧪
API reference for the headers module
Headers API
Experimental
This is an experimental feature and may change in the future.
The headers
module provides a unified way to access HTTP headers in both server
and client environments.
Import
Methods
headers()
Returns the headers object that provides access to all request headers.
get(name)
Retrieves the value of a specific header.
Parameters
name
(string): The name of the header to retrieve
Returns
string | null
: The header value if found, null otherwise
has(name)
Checks if a specific header exists.
Parameters
name
(string): The name of the header to check
Returns
boolean
: True if the header exists, false otherwise
entries()
Returns an iterator of all header entries.
keys()
Returns an iterator of all header names.
values()
Returns an iterator of all header values.
Types
Best Practices
- Header names are case-insensitive
- Use the
has()
method to check for header existence before accessing - Consider fallback values when headers might not be present