What are HTTP headers Accept and ContentType in Restful web services
In this tutorial we are going to learn about HTTP Headers: Accept and ContentType in detail.
When we send a HTTP request to create a user profile for example, user details that are being sent are included in HTTP request body.
And this information about the user profile is well structured in the JSON format. So when server side script receives the information it should be able to take this JSON text and convert it into a Java object and for a server side script it must be able to convert this text into a Java object.
It needs to know how to convert and what type of content this HTTP request carries in its body like is it an XML or JSON or some other format or a plain text.
So additionally the structuring of user details into JSON format. We need to tell or include into each HTTP request about the type of content it is carrying and to do that we can use content type HTTP header under Headers section in the POSTMAN.
We can list all the headers into a key value pairs that we need in the HTTP request and first one is called Content Type i.e. key and we specify the value as the required format and we can find all the different content types that HTTP header can carry.
In this example we choose application JSON because our body is in JSON format and when web service responds back with some additional information like user details or if we send the request to get list of all users, this information can also be structured in the form of JSON or XML.
So to decide which content type we expect back can be specified using Accept and we can provide the required format i.e. application/json as the content type we can accept.