HTTP Header
An HTTP header is metadata included in an HTTP request or response. It conveys information like content type, length, encoding, authentication tokens, and caching preferences.
Also known as: Header fields, HTTP metadata.
Comparisons
- HTTP Header vs. HTTP Body: Headers provide metadata, while the body contains the actual content.
- Custom vs. Standard Headers: Standard headers follow predefined formats, while custom headers are user-defined for specific needs.
Pros
- Enhances communication: Specifies data handling preferences.
- Enables authentication: Includes tokens or credentials for secure access.
Cons
- Increased size: Can add overhead to requests and responses.
- Security exposure: Sensitive data in headers can be exploited.
Example
GET /api/data HTTP/1.1Host: example.comAuthorization: Bearer abc123tokenContent-Type: application/jsonUser-Agent: MyApp/1.0Accept: application/json
This HTTP request includes headers like Authorization for authentication, Content-Type to indicate JSON data, and User-Agent to identify the client application. These headers help servers process the request appropriately.