HTTP Request Headers Interview Questions and Answers
Master HTTP Request Headers with the top 15 interview questions and answers. Learn Accept, Authorization, Content-Type, User-Agent, Host, Cookie, Cache-Control, Conditional Requests, Correlation IDs, Spring Boot examples, production best practices, and common interview questions.
Introduction
HTTP Request Headers are key-value pairs sent by the client to provide additional information about an HTTP request. They help servers understand who is making the request, what data format is expected, how authentication should be handled, whether cached data can be used, and much more.
In enterprise applications, request headers are widely used for authentication, authorization, content negotiation, API versioning, distributed tracing, caching, localization, security, and observability.
Interviewers frequently ask developers to explain Content-Type vs Accept, Authorization headers, Correlation IDs, Cache-Control, Conditional Requests, and how Spring Boot reads request headers.
This guide covers the 15 most important HTTP Request Header interview questions with production-ready explanations, Spring Boot examples, architecture diagrams, best practices, and common mistakes.
What You'll Learn
After completing this guide, you'll be able to:
- Understand the purpose of HTTP Request Headers.
- Differentiate commonly used request headers.
- Implement request headers in Spring Boot.
- Explain authentication and caching headers.
- Understand distributed tracing headers.
- Answer REST API interview questions confidently.
HTTP Request Flow
Client
│
HTTP Request Headers
│
┌────────────────┼─────────────────┐
│ │ │
▼ ▼ ▼
Authorization Accept Content-Type
User-Agent Host Cache-Control
Correlation-ID Cookie Accept-Language
│
▼
Spring Boot API
│
▼
Business Logic
│
▼
HTTP Response
1. What are HTTP Request Headers?
Short Answer
HTTP Request Headers are key-value pairs sent by the client that provide additional information about the request.
Example
GET /employees HTTP/1.1
Host: api.company.com
Authorization: Bearer eyJhbGc...
Accept: application/json
User-Agent: Chrome
Production Uses
- Authentication
- Content negotiation
- API versioning
- Localization
- Caching
- Distributed tracing
Interview Follow-up
Why are request headers needed in REST APIs?
2. What is the Accept Header?
Short Answer
The Accept header tells the server which response format the client expects.
Example
Accept: application/json
or
Accept: application/xml
Production Example
Mobile App
↓
Accept: application/json
↓
Spring Boot API
↓
JSON Response
Common Values
- application/json
- application/xml
- text/html
- image/png
3. What is the Authorization Header?
Short Answer
The Authorization header carries authentication credentials.
JWT Example
Authorization: Bearer eyJhbGc...
Basic Authentication
Authorization: Basic dXNlcjpwYXNz
Production Flow
Client
↓
JWT Token
↓
API Gateway
↓
Spring Security
↓
REST API
Common Mistakes
- Sending tokens in query parameters.
- Logging JWT tokens.
- Using HTTP instead of HTTPS.
4. What is the Content-Type Header?
Short Answer
Content-Type specifies the format of the request body sent to the server.
Example
Content-Type: application/json
JSON Request
{
"name":"John",
"salary":90000
}
Spring Boot Example
@PostMapping(
consumes = "application/json")
public Employee save(
@RequestBody Employee employee){
return service.save(employee);
}
Interview Tip
Content-Type describes the request body.
Accept describes the expected response.
5. What is the Difference Between Accept and Content-Type?
| Header | Purpose |
|---|---|
| Accept | Expected Response Format |
| Content-Type | Request Body Format |
Example
Accept: application/json
Content-Type: application/json
Common Interview Question
Can a GET request have a Content-Type header?
Answer:
Usually no, because GET requests normally don't contain a request body.
6. What is the User-Agent Header?
Short Answer
User-Agent identifies the client application making the request.
Example
User-Agent:
Mozilla/5.0
Production Uses
- Analytics
- Browser detection
- Device compatibility
- Logging
Example
Chrome Browser
↓
Spring Boot
↓
Customized Response
7. What is the Host Header?
Short Answer
Host identifies the server receiving the request.
Example
Host: api.company.com
Production Uses
- Virtual hosting
- Reverse proxies
- Load balancers
Common Interview Question
Why is Host mandatory in HTTP/1.1?
8. What is the Cookie Header?
Short Answer
Cookie sends previously stored client cookies to the server.
Example
Cookie:
SESSION=abc123
Production Example
Browser
↓
Cookie
↓
Server
↓
Session Validation
REST Best Practice
REST APIs generally prefer JWT tokens instead of server-side sessions.
9. What is the Cache-Control Header?
Short Answer
Cache-Control tells servers and browsers how cached data should be handled.
Example
Cache-Control: no-cache
or
Cache-Control: max-age=300
Production Uses
- Browser caching
- CDN caching
- API Gateway caching
10. What are Conditional Request Headers?
Short Answer
Conditional headers reduce unnecessary network traffic by transferring data only when it has changed.
Common Headers
- If-None-Match
- If-Match
- If-Modified-Since
Example
If-None-Match: "abc123"
Server
304 Not Modified
Benefits
- Better performance
- Lower bandwidth
- Reduced server load
11. What is a Correlation ID?
Short Answer
A Correlation ID uniquely identifies a request across multiple services.
Example
X-Correlation-ID:
12345-ABCDE
Production Flow
Client
↓
API Gateway
↓
Order Service
↓
Payment Service
↓
Notification Service
All services log the same Correlation ID.
Benefits
- Easier debugging
- Distributed tracing
- Centralized logging
12. What is the Accept-Language Header?
Short Answer
Accept-Language tells the server which language the client prefers.
Example
Accept-Language: en-US
or
Accept-Language: fr-FR
Production Example
International banking applications.
Global e-commerce platforms.
13. How are Request Headers Read in Spring Boot?
Example
@GetMapping("/profile")
public String profile(
@RequestHeader("Authorization")
String token){
return token;
}
Multiple Headers
@GetMapping("/info")
public String info(
@RequestHeader("User-Agent")
String agent,
@RequestHeader("Accept")
String accept){
return "Success";
}
14. What are Common Request Header Mistakes?
- Sending authentication tokens in URLs.
- Missing Authorization header.
- Confusing Accept and Content-Type.
- Logging sensitive headers.
- Ignoring HTTPS.
- Missing Correlation IDs.
- Using inconsistent custom header names.
- Sending invalid MIME types.
15. What are Request Header Best Practices?
- Always use HTTPS.
- Never expose sensitive headers.
- Use JWT for authentication.
- Include Correlation IDs.
- Use proper MIME types.
- Validate client headers.
- Support content negotiation.
- Avoid unnecessary custom headers.
- Follow HTTP standards.
- Document required headers in OpenAPI.
Common Request Headers Summary
| Header | Purpose |
|---|---|
| Accept | Expected Response Format |
| Authorization | Authentication |
| Content-Type | Request Body Format |
| User-Agent | Client Information |
| Host | Target Server |
| Cookie | Session Information |
| Cache-Control | Caching |
| If-None-Match | Conditional Request |
| If-Modified-Since | Cache Validation |
| Accept-Language | Preferred Language |
| X-Correlation-ID | Distributed Tracing |
Interview Tips
When discussing HTTP Request Headers:
- Explain that headers provide metadata about the request.
- Differentiate Accept and Content-Type.
- Explain Authorization with JWT.
- Discuss Correlation IDs in microservices.
- Mention conditional requests and caching.
- Demonstrate reading headers using
@RequestHeader. - Explain why HTTPS is required for sensitive headers.
- Use production examples from Spring Boot and API Gateways.
Key Takeaways
- HTTP Request Headers provide metadata that helps servers process requests correctly.
- Accept specifies the desired response format, while Content-Type specifies the format of the request body.
- Authorization headers securely carry authentication credentials such as JWT tokens.
- User-Agent identifies the client application or browser.
- Host identifies the destination server in HTTP/1.1.
- Cache-Control and conditional request headers improve performance by reducing unnecessary network traffic.
- Correlation IDs are essential for distributed tracing and debugging in microservices.
- Spring Boot provides
@RequestHeaderto easily access request headers. - Secure handling of request headers is critical for enterprise REST APIs.
- Understanding request headers is essential for Java, Spring Boot, Microservices, and REST API interviews.