Search code examples
c#asp.net-web-apibackwards-compatibility

Adding parameters and backward compatibility?


Using WebAPI I have a restful service.

public SomeValue GetSomeValue()
{
}

I need to now pass in a string, but it's optional and a default value is fine:

public SomeValue GetSomeValue(string language="EN")
{
}    

Will old clients that I can't update send a call just to GetSomeValue() still work, with a default value sent in? Or do I need to create a second method GetSomeValueForLanguage(string language) with GetSomeValue() calling it internally?


Solution

  • Change the method to take a default string parameter; old clients will be able to call it fine still, assuming your routing is staying the same (in which case language will be appended to the query string). If you're adding language as a route token, ensure that it's optional on the route such that the default parameter value for the action is used.