users@jsr311.java.net

sub resource locators & generating urls

From: Jo Størset <jo.storset_at_usit.uio.no>
Date: Tue, 8 Jul 2008 00:43:54 +0200

Hi,

there must be some things I misunderstand (maybe my architectural idea
is all wrong :).

The best way to clear things up is probably to give a simple example.
So i have a resource domain, and part of it is something like:

/keywords/{keyword}/researchers
/researchers/{id}/keywords

with resources on all segments. Basically /keywords would list the
keywords, /keywords/{keyword}/researchers would list the researchers
tagged with the keyword (with urls to /researchers/1 etc.), and so on.

1) If I wanted to have a Keywords and a Keyword class I can
     - use a sub resource locator, but then I have to give up all
support for DI or 'pollute' the parent with the child's dependencies?
     - duplicate the path in the two classes?

How should I model this effectively?

2) When I want to supply a representation of a researcher's keywords,
I want to give out url's to them (after all, it's the web :)

If I use sub resource locators, there is no way of doing this except
hard coding the concatenated path elements (or something equivalent)
in the representation rendering logic? Does this mean i'm stuck with
not using sub resource locators?

I am thinking that effective means of using the same mechanism for
request mapping and url generation must be important for a rest api?
But maybe it's to difficult or to early days?

3) I have tried to create my own framework for generating path-based
urls:

My app is layered, with the resource classes calling a service facade
returning domain objects. These domain objects have a mapping to their
corresponding resource classes, and an identified property mapping to
path segments.

The service call to get a keyword's researchers, returns researcher
objects. These are mapped to the researcheResource annotated with
path /researchers/{id} . I then have a jaxb writer with a listener
that recognizes domain objects and their resource mapping, and writes
the url.

This is working as long as I the @path annotations are resonably simple.

Is this something anybody else is doing?

Jo