Beginner LevelREST APIs & Web Services
How does Content-Type and Accept Header Negotiation work in REST APIs?
❓ Interview Prompt: Explain MIME types, `Content-Type` header (request body format) vs `Accept` header (expected response format), and 415/406 status codes.
HTTP Header Negotiation allows clients and servers to agree on payload representation data formats using MIME media types:
Key Headers:
•
'Content-Type': Tells the receiver how to parse the incoming request body (e.g. 'application/json', 'multipart/form-data'). If server unsupported $\rightarrow$ Returns '415 Unsupported Media Type'.
•
'Accept': Tells the server what format the client expects in the returned response (e.g. 'Accept: application/json, text/csv'). If server cannot produce format $\rightarrow$ Returns '406 Not Acceptable'.
Code Implementation Example
http
POST /api/v1/reports HTTP/1.1
Host: api.example.com
Content-Type: application/json
Accept: text/csv
{ "dateRange": "2026-07" }💡Request specifying JSON input payload and requesting CSV output format.
🎯 Interview Key Takeaway
Content-Type specifies incoming request payload format; Accept header requests desired response format.
#Content Negotiation#HTTP Headers#MIME Types#Beginner
Back to all REST APIs & Web Services Questions→