Web API response formatting

2014-01-19 Thread Greg Keogh
Folks, what is the recommended way of letting the caller choose the format of the response? I have a method that can return plain text or XML, so how does the caller choose the one they want? I could have a format= parameter on the method call (Rackspace do that), or is it better to inspect the

Re: Web API response formatting

2014-01-19 Thread Dave Walker
Accept header is the norm On 20 January 2014 15:03, Greg Keogh g...@mira.net wrote: Folks, what is the recommended way of letting the caller choose the format of the response? I have a method that can return plain text or XML, so how does the caller choose the one they want? I could have a

Re: Web API response formatting

2014-01-19 Thread Jamie Surman
...@mira.net To: ozDotNet ozdotnet@ozdotnet.com Sent: Monday, 20 January 2014 3:03 PM Subject: Web API response formatting Folks, what is the recommended way of letting the caller choose the format of the response? I have a method that can return plain text or XML, so how does the caller

Re: Web API response formatting

2014-01-19 Thread Greg Keogh
Chaps, after some doodling around I see I can get the Accept values straight out of the Request in the controller's code. That does now seem to be the logical way of choosing the response format. More confusion though ... I tried to write a controller method that returned either plain text or

Re: Web API response formatting

2014-01-19 Thread Greg Keogh
Please ignore previous message as I hit Send instead of Save (bloody Gmail interface!). Here's the correct message: Chaps, after some doodling around I see I can get the Accept values straight out of the Request in the controller's code. That does now seem to be the logical way of choosing the

Re: Web API response formatting

2014-01-19 Thread David Burstin
Greg, let the web API deal with the formatting. Your controller should ideally just return an object which will be formatted according to the request. (apologies for brevity, I am playing mini golf with my son) Try it in Fiddler and you can see how changing the request will change the output. If

Re: Web API response formatting

2014-01-19 Thread David Burstin
From my limited reading on this I think you will struggle to remove the xmlns, the rationale being that without a namespace the xml is not valid. While technically true, it is also annoying. Personally I have a strong preference for JSON these days and use it whenever I can... simple, ubiquitous