The Web API has a function that automatically binds the argument sent to the action inside the controller. This is called parameter binding . It allows you to simply request an object inside the URL or body of the POST request, and it uses the deserialization magic for you using a thing called Formatters. There is a formatter for XML, JSON, and other well-known types of HTTP requests.
For example, let's say I have the following JSON:
{ "SenderName": "David" "SenderAge": 35 }
I can create an object that matches my query, we will call it SenderDetails :
public class SenderDetails { public string SenderName { get; set; } public int SenderAge { get; set; } }
Now, having received this object as a parameter in my POST action, I tell WebAPI to try to bind this object for me. If all goes well, I will have the information available to me without parsing it:
[Route("api/SenderDetails")] [HttpPost] public IHttpActionResult Test(SenderDetails senderDetails) {
source share