Content negotiation is theprocessby which the application returns data in a format that is requested by the client. This is usually done for API-style invocations, not requests that serve HTML. For example, a certain client might want data returned in JSON format, while others might prefer XML. ASP.NET Core supports this.
There are essentially two ways to achieve this:
- Through a route or query string parameter
- Through theAccept request header
The first approach lets you specify the format that you're interested in on the URL. Let's see how this works first:
- Say you have the following action method:
public Model Process() { ... }
- Let's forget whatModelactually is as it's just a POCO class that contains the properties you're interested in. It could be as simple as this:
public class Model
{
public...