I would like to get the MediaTypeFormatter from the request object, is this possible ?
So if the request came in as a
application/json
then I would like to get the MediaTypeFormatter which should be, in this case, a JsonMediaTypeFormatter.
The reason I need to do this is so that my api methods can support both MediaTypeFormatters (i.e. XML and JSON).
I am returning a HttpResponseMessage and settting the Content to ObjectContent and i am required to pass in the media type formatter, if i hard code this value to json then it isn't going to support xml.
Anyone done something like this ?
Thanks in advance
Accept
header sent in the request. You should not need to be concerned with setting the response content type in your API methods unless you're doing something special. Let the framework handle it; that is what it is designed for. See @Badri's answer. – Brian Rogers