What is Content negotiation in web api?

Content negotiation mean get data in a format that client need..

content negotiation is the mechanism that is used for serving different representations of a resource at the same URI

We need to tell the service by defining in Request header.For example we want a service to return data in XML format and Json at another time with same service. So to achieve this we will send corresponding Content-type as below..

For Json

Content-type: application/json

For XML

Content-type: application/xml

When we send these Content-type web api checks the request header and response accordingly with the help of MediaFormatter in .Net.

Similarly getting desired image for mate,document formats,language etc. Can be considered Content negotiation.

Difference between WCF and Web API

WCF:

  1. We can use Http,Tcpip,msmq protocol.
  2. It is recommended when we need transaction or need to develop chat services etc.
  3. WCF need lot of configuration.

Web API:

  1. It uses only Http protocol.
  2. It is recommended when service to be consumed on web,mobile or on low bandwidth devices.
  3. We don’t need too much configuration like WCF.