tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Soto <asot...@gmail.com>
Subject JaxRS versioning REST API
Date Sun, 19 Oct 2014 11:19:03 GMT
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
+----------------------------------------------------------+

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message