Re: Web API Accept type

2015-08-18 Thread Greg Keogh

 I would provide two different methods. It's easier for you and easier for
 the end developers to understand.


In the end I sort of did that. It's best not to fight the system, so I
changed the method so that it simply returns a serialized object (a rather
complicated one), but no matter what format the request asks for I just let
the infrastructure pick the serializer and return it. I don't even tamper
with the shape of the JSON or XML that's returned. Yeah, *don't fight the
system* if you can avoid it! -- *GK*


Re: Web API Accept type

2015-08-18 Thread Davy Jones
I would provide two different methods. It's easier for you and easier for the 
end developers to understand.

Davy

Sent from my iPhone

 On 17 Aug 2015, at 23:56, Greg Keogh gfke...@gmail.com wrote:
 
 Folks, in Web API when you sent an object back in the response it's 
 automatically serialized as JSON or XML depending upon the Accept header. 
 This is great, but I have to cheat the system slightly and send back manually 
 tweaked XML only if the XML serializer is active. Rather than look at the 
 raw text of the request Accept headers, is there is more formal way of 
 knowing which serializer is active (if this means anything) -- GK


Re: Web API Accept type

2015-08-18 Thread Nelson
Hi Greg,


Sounds like this is what you want:
http://www.asp.net/web-api/overview/formats-and-model-binding/media-formatters

You can define your own media formatter to customise your response for
particular types


Regards,

Nelson Chan

On 18 August 2015 at 20:04, Greg Keogh gfke...@gmail.com wrote:

 I would provide two different methods. It's easier for you and easier for
 the end developers to understand.


 In the end I sort of did that. It's best not to fight the system, so I
 changed the method so that it simply returns a serialized object (a rather
 complicated one), but no matter what format the request asks for I just let
 the infrastructure pick the serializer and return it. I don't even tamper
 with the shape of the JSON or XML that's returned. Yeah, *don't fight the
 system* if you can avoid it! -- *GK*



Re: Web API Accept type

2015-08-17 Thread Bec C
Is you tweak of the xml generic, ie. will happen to every xml response?
If so I'd imagine the method would be to override the default xml
serializer (or implement some interface) and tell web api to use your one
instead of the default. Testing which one is active by any means just seems
hacky. Or perhaps I've misunderstood

On Tue, Aug 18, 2015 at 7:56 AM, Greg Keogh gfke...@gmail.com wrote:

 Folks, in Web API when you sent an object back in the response it's
 automatically serialized as JSON or XML depending upon the Accept header.
 This is great, but I have to cheat the system slightly and send back
 manually tweaked XML only if the XML serializer is active. Rather than
 look at the raw text of the request Accept headers, is there is more formal
 way of knowing which serializer is active (if this means anything) --
 *GK*