users@jersey.java.net

Re: How to retrieve list of resources - use MatrixParams?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 17 Mar 2008 14:28:06 +0100

Martin Grotzke wrote:
> On Tue, 2008-03-11 at 13:49 -0400, Marc Hadley wrote:
>> On Mar 11, 2008, at 11:11 AM, Martin Grotzke wrote:
>>> this is of course a possible solution. But isn't comma separation of a
>>> list of resources (like /products/1,2,3) somehow common (in the REST
>>> world)?
>>>
>> There's nothing wrong with it but its not a convention either AFAIK.
> I read this in "RESTful Web Services" (Richardson, Ruby) and thought
> this would be s.th. lots of people would agree on. Is there some
> document that describes ("defines") what is RESTful that "most" people
> agree about (besides Fieldings thesis)?
>

That seems to be a nice way for some types of clean URL but i don't
think it is an agreed convention as much as matrix parameters. Thus i
would prefer not to bake this into the API just yet e.g. as a special
annotation e,g, @CommaParam. As Marc pointed out you can create your own
type to process a comma separated list that is a path segment.

Paul.


> To have a solution for now I would use th query param solution proposed
> by you...
>
> Thanx && cheers,
> Martin
>
>> Marc.
>>
>>> On Tue, 2008-03-11 at 09:50 -0400, Marc Hadley wrote:
>>>> On Mar 11, 2008, at 4:22 AM, Martin Grotzke wrote:
>>>>> thanx for your feedback! Would it be easier if I used s.th.
>>>>> like /products/123,234,345?
>>>>>
>>>> Easiest would be something like
>>>>
>>>> /products?p=123&p=234&p=345
>>>>
>>>> then you could use
>>>>
>>>> UriInfo.getQueryParameters.get("p")
>>>>
>>>> which returns a List<String> with values {"123","234","345"}
>>>>
>>>>> Shouldn't such a basic concept of REST be supported a little bit
>>>>> better
>>>>> - with a higher level of abstraction? If I would have to bother with
>>>>> PathSegements it would be more intuitive to use comma, and simply
>>>>> do a
>>>>> string.split. But this doesn't seem to be what it should be...
>>>>>
>>>> If you used commas then you could define your own type:
>>>>
>>>> public class ProductList<String> extends ArrayList<String> {
>>>> public ProductList(String commaSeparatedList) {
>>>> // do the string split and add elements
>>>> }
>>>> }
>>>>
>>>> Then you can write
>>>>
>>>> @Path("products/{ids}")
>>>> public class ProductListResource {
>>>> @GET
>>>> public XXX get(@PathParam("ids") ProductList<String> list) {...}
>>>> }
>>>>
>>>>
>>>>> So is this an outstanding issue of the spec?
>>>>>
>>>> I don't think so, the spec already supports the ability to add types
>>>> to support a variety of URI styles.
>>>>
>>>> Marc.
>>>>
>>>>
>>>>> On Mon, 2008-03-10 at 17:03 -0400, Marc Hadley wrote:
>>>>>> On Mar 10, 2008, at 4:45 PM, Martin Grotzke wrote:
>>>>>>> I want to allow the user to retrieve a list of specified products
>>>>>>> under
>>>>>>> a URL like this: /products/123;234;345
>>>>>>>
>>>>>>> How is this possible with jersey?
>>>>>>>
>>>>>> Semicolon is used to mark the start of matrix parameters in a URI
>>>>>> path
>>>>>> segment. Try something like:
>>>>>>
>>>>>> @Path("/products/{id}")
>>>>>> public class ProductList {
>>>>>>
>>>>>> @Context
>>>>>> UriInfo uri;
>>>>>>
>>>>>> @GET
>>>>>> public XXX get(@PathParam("id") String id) {
>>>>>> // id contains the first product (123 above)
>>>>>> List<PathSegment> segs = uri.getPathSegments();
>>>>>> PathSegment p = segs.get(segs.size()-1);
>>>>>> Set<String> ids = p.getMatrixParams().keySet();
>>>>>> // ids contains the rest of the ids (234, 345 above)
>>>>>> return ...
>>>>>> }
>>>>>>
>>>>>> Marc.
>>>>>>
>>>>>> ---
>>>>>> Marc Hadley <marc.hadley at sun.com>
>>>>>> CTO Office, Sun Microsystems.
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>>
>>>> ---
>>>> Marc Hadley <marc.hadley at sun.com>
>>>> CTO Office, Sun Microsystems.
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>> ---
>> Marc Hadley <marc.hadley at sun.com>
>> CTO Office, Sun Microsystems.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>

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