I am trying to migrate an old api to webapi. Problem is that experience is limited so I am here asking this question.
The current api accepts a json payload in a single url. Say /api. The json payload has the following structure
{'action': 'login', 'username': 'user1', 'password': 'password1'}
This should have been a route like /api/login so I could do something like
[Route("api/Login")]
public string Login(Login login)
and define a class for deserialization like
class Login
{
public string username{ get; set; }
public string password{ get; set; }
}
So I made a Route to accept [FromBody] payload and I am stuck finding a way to deserialize the object in a nice way depending on the action.
Every payload could be a valid serializable object with the way I describe If the action key is removed from the payload.
Any suggestions that will not generate ugly code? Please no api rewrite or v2 answer. If I could do it I wouldn't ask this.