I have a method definition:
public async Task<IHttpActionResult> FindUsers([FromBody]User user)
This uses a class:
public class User
{
public string UserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
I would like to extend the functionality of this without breaking the existing endpoint for current clients.
All clients make requests to the RESTful endpoint using an instance of System.Net.Http.HttpClient. They accept the JSON response and deserialize it into a list of User instances:
var user = JsonConvert.DeserializeObject<User>(content);
I would like to add a property to the User class:
public IList<string> Countries { get; set; }
I do not want this to break the endpoint for existing clients. That is, I want them to be able to continue deserializing into instances of their User class without problems.
I would also like them to be able to deserialize into an updated version of the User class if they wish to take advantage of the updated functionality.
The extended functionality would be implemented in the endpoint. It would detect if the Countries list has been provided in the request and, if so, perform a different operation and, thus, return a response - one which includes the Countries list.
Is this possible to do without breaking the endpoint for existing clients?
JsonConvert.DeserializeObjectit isn't an issue. Even if you passCountriesas a member to an client that doesn't want it it will not break. However, you will give the client more data than he/she asked for. I'm only saying that you can returnCountriesto all your clients without breaking any code.