Home > OS >  change api routing of an specific endpoint
change api routing of an specific endpoint

Time:10-15

I have an api routing that works so far:

    config.Routes.MapHttpRoute(
        name: "MyApi",
        routeTemplate: "api/v1/{param}/string1/string2",
        defaults: new { controller = "MyApi", ... })

In the controller, I have a post method that works fine, but I need to modify it, which is fine and it does work. The problem is the following:

I need to leave the old version of the endpoint for compatibility purposes, creating a new endpoint with the following route: "api/v2/{param}/string1/string2". I deally, I would like to have them on the same controller (file), so I thought in using [Route("...")] but unfortunately, this only adds strings to the route, and what I need is to substitute v1 for v2 on the route, is there any way of doing this?

I thought in a workaround that is creating a new controller with the new route, same parameters, but it will have to be in another file, instead of keeping them together. Any suggestions or this is the only way of doing it? Thanks in advance. Unfortunately, target network is 4.7.2

CodePudding user response:

Firstly, I don't think you can realize the version control only with some configurations but not adding a new method or new controller as I really failed to find it in official document. And if you insist on keep the method unique that you won't add a new method or file, you may take enter image description here

  • Related