Skip to content

HTTP Header

In one line

An HTTP header is a key-value pair that sends metadata about a request or response, such as content type, caching, and authentication.

In simple words

HTTP headers are metadata sent with every HTTP request and response. They provide information about the data being sent — its type, size, encoding, caching rules, authentication tokens, and more. Headers are key-value pairs separated by a colon.

Common request headers include: Host (the domain), User-Agent (browser info), Accept (expected content type), Authorization (credentials), and Content-Type (body format for POST/PUT). Common response headers include: Content-Type, Content-Length, Cache-Control, Set-Cookie, and Location (for redirects).

Headers are essential for proper HTTP communication. In JavaScript, you can set request headers with the Fetch API and read response headers with response.headers.get('name'). Some headers are restricted for security reasons and cannot be set from JavaScript.

Example

http
GET /api/users HTTP/1.1
Host: api.example.com
Accept: application/json
Authorization: Bearer token123
User-Agent: Mozilla/5.0

---

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=3600

Request headers (Host, Accept, Authorization, User-Agent) and response headers (Content-Type, Cache-Control).

Related terms

Related Resources

Related Lessons

  • HTTP

    HTTP protocol and headers.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary