Re: Content Negotation vs. Extensions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 26 Apr 2007 12:38:55 +0200

Stefan Tilkov wrote:
> I know the "right" way to do return different representations of a
> resource is via content negotiation. Still, in many cases it's perceived
> to be easier to use different extensions for different types.
> E.g. I could do a GET on to get the
> default representation, say in HTML, and use
> to get an XML representation.
> Whether this is "good" or "bad" doesn't really matter IMO; it's going to
> definitely a common approach. How do we address this?

Good question.

We could do this with sub-resources for separate methods in much the
same way as there could be different methods on the same resource for
different productions. For example:

class Customer {

   Customer getAsXML() { return getAsXMLResource(); }

   Customer getAsJSON() { return getAsJSONResource(); }

   Customer getAsXMLResource() { ... }

   JSONObject getAsJSONResource() { ... }


Maybe there is a case for compressing the methods like the following:

class Customer {

   @UriTemplates("", ".xml")
   Customer getAsXML() { return ... }

   @UriTemplates("", ".json")
   Customer getAsJSON() { return ... }

Although i do like the way '_at_UriTemplates("", ".xml")' expresses things
but could not think of anything better in the few minutes of thought
about it.

However, the current matching algorithm i proposed (in the attached HTML
document sent in a previous email) would not work as sub-resources are
separated as path segments in the URI path hierarchy as the paths would be:


not good!

So we would need a way to distinguish between path segments and non-path
segments for HTTP methods that are marked as sub-resources, perhaps
requiring things to being with a "/" ? (which just for URI
template-based HTTP methods is a very easy fix to the implementation of
the algorithm).


> Stefan
> --
> Stefan Tilkov,
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

| ? + ? = To question
    Paul Sandoz