Reputation: 1435
We want to version our REST API. The version is for the whole API and not for a single resource.
I thaught of having a javax.ws.rs.core.Application for every API version, which then referes to the resources it exposes.
- com.foo.bar.rest.v1
- MyApiApplicationV1
- MyResourceOne (Path: /api/one; X-VERSION: 1)
- MyResourceTwo (Path: /api/two; X-VERSION: 1)
- com.foo.bar.rest.v2
- MyApiApplicationV2
- MyResourceOne (Path: /api/one; X-VERSION: 2)
- MyResourceThree (Path: /api/three; X-VERSION: 2)
The Version of the API is passed in the X-Version header.
My question is: is it possible to activate MyApiApplicationV1 if the X-VERSION header is 1 and MyApiApplicationV2 if the X-Version header is 2? How to?
We're using JAX RS 2 / RESTeasy 3
Thanks
Upvotes: 2
Views: 1380
Reputation: 10961
A JAX-RS application is mapped to a path usually by web.xml configuration or by using @ApplicationPath. If the path identifies your application you can't have two applications running on the same path.
To workaround this you could add a third application or a simple servlet which redirects to the appropriate version depending on your version header.
Unrelated: Here's a good talk about if and when versioning of RESTful APIs makes sense (starting at 00:26).
Upvotes: 1