users@jersey.java.net

Re: [Jersey] Optional PathParam is it possible?

From: Dário Abdulrehman <dario.rehman_at_gmail.com>
Date: Thu, 18 Feb 2010 15:51:37 +0000

On Thu, Feb 18, 2010 at 9:34 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

>
> On Feb 18, 2010, at 12:40 AM, Dário Abdulrehman wrote:
>
> Given the following resource method:
>>
>> @GET @Path("tfs/{tf : .*}/genes/{gene : .*}/evidence_codes/{evidence_code:
>> .*}")
>> public Response doGet(@Context Request req,
>> @PathParam("tf") List<PathSegment> tfs, @PathParam("gene")
>> List<PathSegment> genes,
>> @PathParam("evidence_code") List<PathSegment> ecs,
>>
>>
>> I would like to make each one of the PathSegments optional (tfs/, genes/
>> and evidence_codes/), however like it is now, if I don't provide for
>> instance, any genes,
>>
>
> Are they independently optional? if so why not use query parameters?


> Or is there a hierarchical dependency? for example if "genes" is present
> then "tfs" must be present? If so may need to be explicit and do:
>
> @Path("tfs/{tf : .+}")
>
> @Path("tfs/{tf : .+}/genes/{gene : .+}")
>
> @Path("tfs/{tf : .+}/genes/{gene : .+}/evidence_codes/{evidence_code:
> .+}")
>
>

No they are not independently optional.

Is it good REST design to represent non-hierarchical data using
PathSegments?
An URI suggests a hierarchy but designing a URI path like
resource/gene1/gene2/gene3.... etc where each gene is at the same level
breaks that notion or am I being too strict?
Are there any examples of APIs where this is used?
Thanks.




>
> Here is a bit of regex from "Master Foo" that you could use to match path
> segments optionally and independently:
>
> @Path("{a : (?:a/.+?)?}{b : (?:/b/.+?)?}{c: (?:/c/.+?)?}")
>
> "Master Foo" will not tell me how to modify this such that if "a" is
> present "b" and "c" may or may not be present, and if "b" is present "c" may
> or may not be present. He says the path to regex enlightenment must be found
> within oneself :-)
>
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>