dev@jersey.java.net

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

From: Peter Liu <Peter.Liu_at_Sun.COM>
Date: Fri, 05 Oct 2007 11:10:52 -0700

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