users@jersey.java.net

[Jersey] Re: Adding versioning support in jersey rest

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 07 Jul 2011 15:49:41 +0200

On 07/02/2011 07:17 PM, Christopher Currie wrote:
> AFAIK jersey doesn't do request routing on query parameters. A couple
> of options:
>
> 1. If you're flexible with your API, you can make the version number a
> prefix of the path. Then its a simple matter of having a different
> root resource registered for each version of your API.

That would be one option, another one [1] was suggested
by Gili and Conal.

> 2. If your API is not flexible, then you'll have to do the heavy
> lifting. Your root resource(s) methods will have to accept the
> QueryParam argument, check its value, and return the version-specific
> Resource class as a "subresource". Even though this is a bit of an
> abuse of that mechanic, it should achieve the result. But its a lot
> more work than option 1.
Even if your API is not flexible, i would recommend
implementing one of the above mentioned versioning
methods and implement a special request filter [2]
in addition in order to allow the special version query parameter.
The filter needs to lookup the query parameter in the original
request and return the request updated according
to the selected versioning method.

~Jakub


[1]http://stackoverflow.com/questions/972226/how-to-version-rest-uris/975394#975394
[2]http://jersey.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/container/ContainerRequestFilter.html
> HTH,
> Christopher
>
>
> On 7/2/11, Umesh Bhatt<umesh_bhatt_at_mindtree.com> wrote:
>> Hi,
>>
>> I want to add version support in my rest web service and want to achieve as
>> mentioned below. Please let me know how to achieve it.
>>
>> In URL I want to add QueryParam version and based on this value want to call
>> correct resource. For this I want to create Http request interceptor to
>> check version info and call appropriate resource.
>> Please let me know how to do this.
>>
>> Thanks,
>> Umesh
>>
>> ________________________________
>>
>> http://www.mindtree.com/email/disclaimer.html
>>