4

I have created an application which is exposed as a web service. I am trying to follow REST principles. I am using Spring 4.

What I have done so far is to create my own mime type application/vnd.mycompany-v1+json. From the clients accessing the web service I say which version I want (currently only one).

However, this is not all I need to do. I also need to keep different versions of the resources since I may add/remove properties etc from one version to another. What is the approach to solve this? Do you create a package for each version?

com.mycompany.web.resources.v1.Bike, com.mycompany.web.resources.v2.Bike, etc? This approach would work I guess but the number of versions is not known in this stage so it could be a large list of duplicates. I don't know if this is a problem or if it is the way it must be?

I guess I am not the first one thinking of versioning the resources too so how is this handled?

Andreas
  • 2,450
  • 1
  • 18
  • 20
  • First, what you're asking can be accomplished...I remember seeing Ben Hale give a talk at SpringOne last September. Second, it's a *horrible* idea to keep multiple versions of the same software running live, since you can easily have divergent yet exactly similar code which has some bug patches between them, but not across the board. – Makoto Feb 05 '14 at 17:55
  • I suggest editing your question to clarify that you are versioning a *library* for accessing your API, not that you are trying to version the API itself. – Charles Feb 05 '14 at 22:10
  • @Charles Okey, I changed the question to be clearer. – Andreas Feb 06 '14 at 16:48

1 Answers1

0

You should keep different versions by adding versioning information in resource url. Something like http://yourserver/app/v1/..

The reason you should include versioning in your api is that some of the clients may already be using your previous version and do not want to upgrade. This is more for adding flexibility in your api design. Ofcourse as an api provider you can always declare that you will not support version x from now onwards.

csn
  • 376
  • 7
  • 18
  • This is already handled by the Accept header of the clients and content type header set by the server. I don't like the approach of keeping it in the URL like that. Any how the question is what I should do with the resources. – Andreas Feb 05 '14 at 17:57