HTTP Headers: Request Headers
You'll learn what request headers are and how the most important ones—Host, User-Agent, Accept, and Content-Type—help clients communicate with servers.
What Are Request Headers?
When your browser sends an HTTP request to a server, the request line (method, path, version) tells the server what you want. Request headers provide context—they're metadata that describe the client's capabilities, preferences, and the nature of the request itself.
Think of request headers like writing a letter: the main body says what you want, but the envelope and letterhead provide crucial information about who's sending it, what language you prefer for the reply, and how to respond.
Key Request Headers
Host
The Host header specifies which domain name the client is requesting. This is required in HTTP/1.1 because one server might host multiple websites (virtual hosting).
Host: www.example.com
User-Agent
Identifies the client software making the request—typically the browser name and version. Servers use this to tailor responses or track usage statistics.
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)
Accept
Tells the server what content types (MIME types) the client can handle. The server tries to respond with a matching format.
Accept: text/html, application/json
Content-Type
Describes the format of data being sent in the request body (used with POST/PUT). This tells the server how to parse the incoming data.
Content-Type: application/json
Key Takeaway: Request headers like Host, User-Agent, Accept, and Content-Type provide essential context about the client's identity, capabilities, and data format, enabling servers to properly process and respond to HTTP requests.