Header parameters: "Accept" and "Content-type" in a REST context
The difference can be found in the specifications, in this case RFC 7231:
5.3.2. Accept
The "Accept" header field can be used by user agents to specify response media types that are acceptable.
3.1.1.5. Content-Type
The "Content-Type" header field indicates the media type of the associated representation
The Accept
header always indicates what kind of response from the server a client can accept. Content-type
is about the content of the current request or response, depending on which kind of HTTP message it is applied.
So if a request has no payload, you don't have to send a content-type request header, and the same goes for your response: no body, no header necessary.
Some servers may require you to provide a content-type in a request even if the request has no payload; the sever should return a 415 Unsupported Media Type
response if you omit it.
TL;DR
The entity header Content-Type
is used to indicate the media type of the resource. In responses, a Content-Type
header tells the client what the content type of the returned content actually is. In requests, such as POST or PUT, the client tells the server what type of data is actually sent.
Elaborated Answer
As you correctly note, the Accept
header is used by HTTP clients to tell the server what response media types are acceptable. The server, on their turn, will then send back a response, which will include the Content-Type
header telling the client what the media type is actually returned.
Now, the Content-Type
header could be on request and responses as well. Why? Well, think about POST or PUT requests. With those request types, the client is actually sending a bunch of data to the server as part of the request, and the Content-Type
header tells the server what the data actually is and thus determines how the server will parse it.
Accept header is used by HTTP clients to tell the server which type of content they expect/prefer as response. Content-type can be used both by clients and servers to identify the format of the data in their request (client) or response (server) and, therefore, help the other part interpret correctly the information.