Hi What about sub resource locator pattern?
For versioning I used a sub resource facade delegating to the real service then. This is just a router but it allows to put all the logic in a single place. Romain Manni-Bucau Twitter: @rmannibucau Blog: http://rmannibucau.wordpress.com/ LinkedIn: http://fr.linkedin.com/in/rmannibucau Github: https://github.com/rmannibucau 2014-10-19 13:19 GMT+02:00 Alex Soto <[email protected]>: > Hi guys, > > this is more a design question than a question about how to do something > with JAX-RS. > > Currently I am developing an API using JAX-RS which must be versionable. > That means that the API will evolve and client must specify which version > of the API want to use. There are a lot of strategies but finally I decided > to use the one using Header and ContentType. Let me show an example: > > @Consumes*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json" > *})* > > @Produces*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json" > *})* > > *public* *class* Book*RestfulService* *{* > > > > @GET > > @Path*(*"/books"*)* > > …. > > } > > @Consumes*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json" > *})* > > @Produces*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json" > *})* > > *public* *class* Author*RestfulService* *{* > > > > @GET > > @Path*(*“/authors”*)* > > …. > > } > > That's an example of version one, but now let's say I have a modification > only in Author endpoint. I can do it and then the restful will be v2. So I > will have something like: > > @Consumes*({*"application/vnd.blog.v2+xml"*,* "application/vnd.blog.v2+json" > *})* > > @Produces*({*"application/vnd.blog.v2+xml"*,* "application/vnd.blog.v2+json" > *})* > > *public* *class* Author2*RestfulService* *{* > > > > @GET > > @Path*(*“/authors”*)* > > …. > > } > The problem is that because Book has not received any modification, I > should add @Consumes and @Produces with v2 as well, something like: > > @Consumes*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json", > "application/vnd.blog.v2+xml"*,* "application/vnd.blog.v2+json"*})* > > @Produces*({*"application/vnd.blog.v1+xml"*,* "application/vnd.blog.v1+json", > ....*})* > > *public* *class* Book*RestfulService* *{* > > *}* > > So now it is easy but if I have 25 services then I would need to go one by > one and add the media type as well. The problem is that I can miss one and > then the API had a misplaced endpoint. > > One thing that I have thought about it is create a rewriting filter where I > can intercept the calls and then redirect to the correct endpoint. In this > way all the rules will be placed in a single place. > > Any hints/experience on this? > > Thank you so much. > > > -- > +----------------------------------------------------------+ > Alex Soto Bueno > www.lordofthejars.com > +----------------------------------------------------------+
