Understanding Produces And Consumes Attribute In MVC 6
3/08/2019  View: 428
Chia sẻ đến

Produces and Consumes Attributes are newly introduced in MVC 6 (ASP.NET Core) to control the content negotiation. 

What is Content Negotiation?

The process of picking the correct output format is known as Content Negotiation.

Generally, Frameworks will accept two types of input/output formats those are JSON and XML. Nowadays, every framework by default accepts and returns in JSON format because of its advantages. If the user wants to control this default behavior, he should send an Accept Header with an appropriate format in GET or POST request from a client such that Framework will make sure to use the given format.

If a user doesn’t provide any Accept-Header, then the framework will decide which format it should use based on its settings. Some of the most popular browsers such as Chrome and Firefox will by default add Accept Header as application/xml and that is the reason when we call the web API from the browser will display the output in XML format if we don’t explicitly set the output format as JSON.

Below are the sample requests generated from Chrome and IE where can observe the Accept Headers for these two browsers.


CHI TIẾT - READ MORE