Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Ravi Vishwakarma
13-Jun-2025Content Negotiation (or conneg) in ASP.NET Web API is the process of determining the best format (media type) to return in the response, based on what the client can accept.
It's how the server chooses JSON, XML, or other formats based on:
Accept
headerHow It Works
When a client sends a request to the API, it may include an
Accept
header:ASP.NET Web API:
Accept
header.🧪 Example
Request:
Response:
If the client had sent:
Then the server responds with:
Built-in Formatters in Web API
application/json
,text/json
application/xml
,text/xml
You can also create custom formatters for
CSV
,YAML
, etc.Server Configuration (Optional)
You can control or extend formatters in
WebApiConfig.cs
:To remove XML support:
Use Cases
Force Format without Accept Header
You can use URL query strings or route extensions:
Requires custom logic or third-party packages (e.g.,
WebApiContrib.Formatting
).Summary
Accept