users@jersey.java.net

Re: [Jersey] Multiple resource formats

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 30 Jan 2009 17:33:41 -0500

On Jan 30, 2009, at 4:46 PM, Farrukh Najmi wrote:
>
> BTW, do you have an opinion on use of a format QueryParam vs,
> request header. The latter seems the more RESTFul approach but I am
> not sure how a human user can specify request header in a URL.

Right. The Accept header is the HTTP way of specifying the desired
format but browsers don't normally give you the option of specifying
an accept unless you are using something like the Poster plug-in for
Firefox.

> Is there a standard mechanism for encoding HTTP request header param
> values within a URL? If not, and if I need a human to be able to
> specify format in a web browser then it seems the format QueryParam
> is my best option.
>
There's no standard mechanism but there are some conventions. E.g.
Rails uses file extensions like .xml on the end of the URL. We had
some support for that kind of extension-based conneg in pre-1.0 JAX-RS
but Roy Fielding persuaded us that it was a bad idea to include this
in the spec, see the following message and the rest of the thread for
an idea of the tradeoffs:

https://jsr311.dev.java.net/servlets/ReadMsg?list=dev&msgNo=1458

IIRC, Jersey still supports this functionality as an extension however.

If using a query parameter, one approach is to deploy a filter
(Servlet or Jersey) that extracts the value of the query parameter and
uses it to override the Accept header in the request. Then you can
code your JAX-RS application as if Accept were always used and have
the filter do a bit of pre-processing when URL-based conneg is used.

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.