My initial problem . I look at what is the best practice for version control in the Restful API . Not many people talk about this, do not have a good answer, or I can’t find the exact solution at the moment.
(1) First, I think of using Tagor Branchfor each version of http://domain.com/API/ {version}. Therefore, if a new API is released, I Tagexport and publish it in the corresponding URL, but it seems difficult to mix a different version of the source in one web application.
(2) Then I think to use this method, one controller for one version: (Just like this question. REST API versions built into ASP.NET MVC 3 are best practices )
http://domain.com/API/1.0/{AnAction} => will go to APIV1Controller.{AnAction}
http://domain.com/API/2.0/{AnAction} => will go to APIV2Controller.{AnAction}
but he needs to write a route for each version.
(3) Thirdly, I get an idea from the PayPal API, the version of which is not specified in the URL, but in the POST parameter. Therefore, the URL is bound to http://domain.com/API/, but the user must specify a parameter Versionfor "1.0"or "2.0".
The solution for this: (2) is suitable for me, and I'm currently using this method, but I want to mix (2) and (3), so I have an APIController that has only one index action to test this Versionand pass the request to the appropriate controller and the action is either APIV1Controller. {AnAction}, or APIV2Controller. {AnAction}.
Googling Stackoverflow , , . , . - .NET MVC Call , . , reroute!
:
, reroute ?
, http://domain.com/API/{AnAction} Version="2.0", reroute APIController.Index APIV2Controller.{AnAction}?
IoC.