2

I'm working on a small spring mvc project which requires to add api version to the request urls for example: http://host.serice.com/api/1.0/documents. As my understanding i can implement like this:

@RestController
@RequestMapping(value="/api/1.0")
public class DocumentController {
}

In my opinion, it's not a good idea because i have to hard code the version number to all controllers, once the version number increase i have to reupdate the controllers again, this work may violate "open for extension closed for modification" principle. Do you have any idea for this ?

Tien Nguyen
  • 4,298
  • 9
  • 30
  • 44
  • Do you use any build tool like Maven or Gradle? How is your version managed? – Tunaki Oct 02 '15 at 08:08
  • 2
    Possible duplicate of [How to manage REST API versioning with spring?](http://stackoverflow.com/questions/20198275/how-to-manage-rest-api-versioning-with-spring) – Fritz Duchardt Oct 02 '15 at 08:22
  • You can use property placeholders in request mappinng, e.g. `"/api/${api.version}"` so you don't have to hardcode anything if that's your concern. – Bohuslav Burghardt Oct 02 '15 at 09:41
  • Out of curiosity, how did you end up approaching the versioning of your API? – Rick Feb 21 '17 at 20:27

0 Answers0