Content Negotiation in ASP.NET WebAPI

“Good negotiations are very important as they contribute much to business success and build better relations and the aim of any negotiation is to reach to an agreement that results in mutual benefits.”

From the rest architecture point of view, it is very important to understand the concept of Content Negotiation in Web API. One of the standards of the REST service is that the client should have the ability to decide in which format they want the response – whether they want the response in XML or JSON etc. This is called Content Negotiation.

How Content Negotiation Works

There are two main headers which hold the responsibility of content negotiation

  • Content-Type
  • Accept

Let’s try to understand them. When a requester send a service request, the CONTENT-TYPE tells responder the format he will receive data whereas the ACCEPT header tells in which format the requester requires the data.

This image has an empty alt attribute; its file name is webapi-negotiationwebapi2-1.png