users@jersey.java.net

[Jersey] Re: ROA Conceptual Questions

From: Conal Tuohy <conal.tuohy_at_versi.edu.au>
Date: Wed, 08 Jun 2011 12:01:23 +1000

On 07/06/11 09:53, Meeraj Kunnumpurath wrote:
> Hi,
>
> I have couple of ROA related questions, I would greatly appreciate
> someone can shed some light on.
>
> 1. I have a URL that can be accessed by mutually exclusive paths. For
> example, a client may search for all the employee by firstName some
> times and lastName some other times. What would be the best way to
> model path parameters on GET without introducing a hybrid RPC model,
> from a REST perspective? for example. /employee/{firstName} and
> /employee/{lastName} are indistinguishable from each other. Or would
> one use query parameters?
Yes - that's exactly what query parameters are used for
> Are query parameters in general considered as an anti-pattern in ROA?
No
>
> 2. I have an order entry system where users add line items to an
> order. First time a line item is added an order should be created,
> subsequent line items are then added to the created order. Based on
> this I have a resource for order and one for line item. My client is
> using GWT. The first tine a line item is added I send a PUT on the
> order resource which returns an order Id, followed by a PUT on the
> line item resource which quotes the order id. Subsequent line item
> additions just do a PUT on the line item resource.
NB the purpose of PUT is to create or update a resource with a URI
specified by the client. If the client chooses the id of the new
resource, then this is appropriate. If the server chooses the id of the
new resource, then you should use POST to another resource (consider it
a factory, or a container), which would return a redirect to the URI of
the new resource. Subsequently, you could PUT to that new URI to update
the resource.
> Even though this works well, the first interaction of a a PUT each on
> order and line item result in two separate HTTP calls and hence are
> not transactionally atomic. Is there a better way to model the resources?
I'm not quite sure what you mean by this, but perhaps you wish to create
a line item AND order by a single HTTP method? Just POST a line item to
the "order-factory" resource, and have it create an order and a line
item resource, and return a redirect to the line item. NB the line item
resource representation should include a hyperlink to the order which it
is a part of. The client application then knows the current line item
and can POST to the order to create new line items.

C


>
> Kind regards
> Meeraj


-- 
Conal Tuohy
eResearch Business Analyst
Victorian eResearch Strategic Initiative
+61-466324297