Precedence order of incoming request in web api handled by Conneg

Hi Geeks
 
A definite question skrikes in mind when you work with WebAPI that how Conneg handles the request each time when multiple formatters match the request.
 
There are certain ways like the Request Accept header, Content-Type header, MediaTypeMapping etc .which consider by the conneg to writing the response
 
The Conneg algorithm has to choose only one formatter in the end.
 
The Default Conneg algorithm has the following precedence order to select the final formatter:
1. Formatter match based on Media Type Mapping.
2. Formatter match based on Request Accept header's media type.
3. Formatter match based on Request Content-Type header's media type.
4. Formatter match based on if it can serialize the response data’s Type.
5. You can also use HttpResponseMessage to send the resposne despite of the Conneg algorithm overwrite it irrespective of the Request’s Accept header media type.
 
Thanks
Kindly reach me on http://www.dotnetpiper.com/ 
Ebook Download
View all
Learn
View all