users@jersey.java.net

Re: Variable response formats

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 06 Dec 2007 10:23:30 +0100

Farrukh Najmi wrote:
>
> My rest interface needs to return responses conforming to different
> media types based upon a responseFormat option.

By "responseFormat option" do you mean the client HTTP Accept header?


> What is the best approach for return type design for methods with GET
> annotation?
>

Do different resources support different media types?

Are the media types fixed or dynamic or both depending on the content?

If you want to support say Atom and an alternative XML format you can do:

   @ProduceMime("application/atom+xml")
   @GET Entry getEntryAsAtom() { ... }

   @ProduceMime("application/xml")
   @GET JAXBBean getAsAtom() { ... }

If the most acceptable response (determined from the client HTTP Accept
header) is "application/atom+xml" then the method "getEntryAsAtom" will
be invoked.

For the 0.5 Jersey release we will be working on better support for
programmatic selection for wild card media types. But it is not fully
implemented yet.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109