0

I went through all good discussion on api versioning here. We decided to put the version number in the URI, for this we now have to support, clients requesting resource without api version in the uri , to the latest version, by default. example:

http://base_uri/api/customers/1234 (with out api version)
http://base_uri/api/v3.0/customers/1234 (default to current version)

Step 1 :To address above: I am thinking of URL rewrite using(url rewrite, jboss valve) please advise if there are any better approaches.

Step 2: Now i need to pre-pend all the @Path annotations with my version number "v1".

@Path("/foo/bar") will now change to @Path("v1/foo/bar"). 

I was thinking of having a place holder in place of version

ex: @Path("{version}/foo/bar") 

and read the version name from a configuration file, while rest-easy is scanning resources and registering. So in future if we move to new version, all we need is to change in one place.

I am looking for best approaches in step1 & step2. any help is greatly appreciated.

I am using Rest-easy,jax-rs 2.0,jboss

Community
  • 1
  • 1
rohith
  • 733
  • 4
  • 10
  • 24

1 Answers1

0

I would suggest step 2, since URL rewriting may be a bit complicated for this requirement. It also adds one more component to maintain. For Step 2, you need to note that annotations take only Constants, since they are evaluated at compile time. So, declare a constant and reuse that in the @Path annotation.

public static final String VERSION_1 = "1.0";//In Constants class.

Then use this in all the Path mappings or any annotations that you have.

@Path("/"+Constants.VERSION_1+"/foo/bar")

Shankar
  • 2,625
  • 3
  • 25
  • 49