Liu, Jervis wrote:
> 
>> -----Original Message-----
>> From: Charles W. Stanton [mailto:[EMAIL PROTECTED]
>> Sent: 2008年1月15日 23:38
>> To: [email protected]
>> Subject: REST with different return formats
>> 
>> 
>> I want to write RESTful services, utilizing some of the same Service
>> classes
>> I've written for our GWT client, and I need to be able to return either
>> XML
>> or JSON based on something in the URL.
>> 
>> For instance:
>> http://myserver/someapp/json/person/{id}
>> or
>> http://myserver/someapp/person/{id}?format=json
>> 
>> Whatever seems to be a good way to do it.
>> 
>> I don't much care at this point if I use JAX-RS or HTTP Binding--or
>> something else--and I'm open to suggestions.  My entire "server" is
>> configured using Spring, so ideally this would happen via some
>> combination
>> of annotations and/or Spring configurations.
>> 
>> I see in the User's Guide, under the section for RESTful Services ->
>> JAX-RS,
>> that I can use annotations to define the return format as either XML _OR_
>> JSON, but how might I defer making that decision until request time?
>> 
> [Liu, Jervis] A beauty of REST services is its ability to serve the same
> resource with multiple representations. One standard way to do this is
> through setting Accept headers in your REST client. I've put a demo in CXF
> to show how to return different content type from same REST service, it is
> located under "samples\jax_rs\content_negotiation". Grab a latest snapshot
> of CXF and try it out. Any feedbacks are highly welcome.
> 
> CXF JAX-RS doc: http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html
> 

I like the idea of being able to override the Accept headers using some
standard optional query parameter so that its easy to try out the different
representations, using GETs using your web browser by just changing the URI.

e.g. adding ?_format=json to overload the Accept headers present etc.

James
-- 
View this message in context: 
http://www.nabble.com/REST-with-different-return-formats-tp14841539p14877930.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to