1

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?

1
  • 1
    Can you try it in a test environment? Commented Apr 9, 2014 at 22:24

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

you can try this:

public classs  MyParams
{
   public string language{set;get;}
}

then change you method to this:

public SomeValue GetSomeValue([FromBody] MyParams obj)
{
     if(String.IsNullOrEmpty(obj.language) obj.language="en";
     //you code
}

if your HTTP method is GET, you shall use FormUrl attribute instead of FromBody attribute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.