dev@jersey.java.net

Re: Anyway to specify optional value in an uri template?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 10 Oct 2007 15:06:19 +0200

Hi Peter,

Ah, i see where you are coming from now.

Is a query always associated with the last 'thing' or can one have:

  /Categories[CategoryName eq foo]/Products[ProductName eq bar]

?

With Jersey you could have two URI templates like this on the collection
resource

   "{id}"
   "q={q}"

  /Categories/1

  /Categories/q=CategoryName eq foo

For "q={q}" if you set limited to false then a match result in the q
variable having the value of the rest of the URI path

  Paul.

Peter Liu wrote:
> Paul Sandoz wrote:
>> Peter Liu wrote:
>>> I am trying to specify an uri template that lets the users specify a
>>> query string
>>> as a uri parameter. For example, @UriTemplate("customers[{query}]").
>>> However, I would like the [{query}] portion to be optional. Is there
>>> anyway
>>> to specify this in jersey?
>>>
>>
>> The URI template is only used with the URI path component (scoping
>> should only be done using the URI path).
>>
>> If you want access to the query parameters of the URI query component
>> you can use the @QueryParam annotation for specific query parameters.
>> The @DefaultValue annotation can be used in conjunction with a
>> @QueryParam to provide a default value in the absence of a parameter
>> in the query component. To access to all the query parameters use
>> UriInfo.getQueryParameters(). In either case you don't have to worry
>> about parsing the query component.
>>
>> If you want the query parameters to be described in the WADL then it
>> is best to be explicit and use QueryParam on a constructor or a method.
>>
>> Paul.
>>
> Didn't get a chance to respond the past couple of days.
> I am aware that we can use @QueryParam to specify the query. What I am
> trying to do is emulate Microsoft
> Astoria's URI syntax. For example, with Astoria, you can have URIs as
> follows:
>
> .../Categories
> .../Categories[1]
> .../Categories[CategoryName eq foo]
> .../Categroies[1]/Products[ProductName eq bar]
>
> The nice thing about Astoria's approach is that you can specify a query
> in each segment of the URI.
> Basically, it lets you run database queries without using SQL. Anyway,
> I am going to write up
> an analysis comparing Astoria and NB's approach and we can discuss this
> further.
>
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: dev-help_at_jersey.dev.java.net
>

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