GET call on REST API with Accept as text/csv and content-Type as application/json. In what format should the reponse be?

user2921591 picture user2921591 · Mar 23, 2017 · Viewed 7.4k times · Source

GET call on REST API with Accept as text/csv and content-Type as application/json. In what format should the reponse be?

Should the response be in JSON format or in CSV format?

Answer

Aitor Viana picture Aitor Viana · Mar 23, 2017

In HTTP, the Accept header is used by the client to tell the server what content types they'll accept. The server will then send back the response and will set the Content-type header telling the client the type of the content actually returned.

You might have noticed that Content-type is also included in some HTTP requests. This is because some type of HTTP requests, like POST or PUT, can send data to the server. In this case the client tells the server the type of the content data, using the Content-type header.

Now to your question, a GET request should not have any Content-type header. I hope this is clear after my explanation above.