How does the Accept header differ from Content-Type?
Quick answer
Accept tells a server which response media types the client can handle or prefers. Content-Type identifies the media type of a message body: in a request, it describes the data being sent; in a response, it describes the data returned. For example, a client can send JSON and ask for JSON back using both headers. They answer different questions, so one does not replace the other. [S1] [S2]
The question, the details, the next step.
A practical checklist
Identify whether you are inspecting a request or a response.
If a message has a body, compare it with that message’s Content-Type.
Read a request’s Accept as a response-format preference, not a request-body label.
Check a response’s Content-Type to identify the format of its returned body.
Consult the specific service’s documentation for supported formats and expected headers.
A few more useful answers
Does Accept guarantee the server will return the format I request?
No. Accept expresses formats the client can handle or prefers; it is not a guarantee that the server will return one of them. Check the actual response and the service’s documentation. [S1]
Which header describes JSON I send in a request body?
Content-Type describes the request body’s media type, so for a JSON body the example value is application/json. Whether a particular endpoint accepts it depends on that service. [S2]
Sources
References used for this guide.
- [S1] Accept header — HTTP | MDN developer.mozilla.org · Checked
- [S2] Content-Type header — HTTP | MDN developer.mozilla.org · Checked
