简体   繁体   中英

Versioning resources in REST api

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM