Neelesh Malvi

Neelesh Malvi

  • NA
  • 125
  • 0

Versioning in ASP.net core Web API

Aug 29 2018 3:04 AM
Hello,
 
I am working on versioning part of ASP.net core Web API. I am using custom media type option to achieve this. Let me explain scenario...
 
1) We have a different customers and each customer may want different version of some functionality. For example, I have GetA() function of version V1 and currently all customer using this version. Suddenly one of customer demand some changes for GetA() functionality. So I will write another function with same name with the changes that customer asked for(This is my Version V2). Now In this scenario when customer request for GetA() they should get output from V2. So currently i am handling this scenario as below...
 
Version V1 :
 
[AcceptHeader("application/vnd.XXX.s.v1.0+json", "application/json")]
[HttpGet]
[Route("codes/locations")]
public IActionResult GetA()
{
List<Locations> objLocations = new List<Locations>();
LocationsControl objLocationsControl = new LocationsControl(configuration);
objLocations = objLocationsControl.GetA();
return Ok(objLocations);
}
 
Version V2 :
 
[AcceptHeader("application/vnd.XXX.s.v2.0+json", "application/json")]
[HttpGet]
[Route("codes/locations")]
public IActionResult GetA()
{
List<Locations> objLocations = new List<Locations>();
LocationsControl objLocationsControl = new LocationsControl(configuration);
objLocations = objLocationsControl.GetA();
return Ok(objLocations);
}
 
So now i have another functions like GetB(), GetC() etc which may have these different versions as per customers (for example GetB() having 10 different versions etc). In Future these all functions will have different versions for different customers. For example Customer C1 using Version 1 for GetA() and another customer C2 using Version V5 for GetA(). Similarly for GetB(), GetC() etc.
 
Here I need to advise customer each time, which version to be use and might lead to confusions and issues as well. And also debugging for each version will get more difficult.
 
So is there any efficient way to handle such scenarios?
 
Thanks And Regards
Neelesh Malvi 
 
 

Answers (1)