Shouldn't account contain a json string in this case?
That would depend on the specific Content-Type request header you set when you send the request. For example if you used application/x-www-form-urlencoded which is the default then your request body payload must have looked like this:
={"account":{"email":"awd","password":"awad","isNewsletterSubscribed":false}}
Notice the = character at the beginning. That's one of the biggest weirdest things I have ever encountered. Since you can bind only one parameter from the body if the request the Web API doesn't expect a parameter name, but just the value.
This being said, your request payload looks more like a JSON. So it would make far more sense to design a view model and use Content-Type: application/json when sending the request. Binding a JSON object to a string is not common practice.
So:
public class UserViewModel
{
public string Email { get; set; }
public string Password { get; set; }
public bool IsNewsletterSubscribed { get; set; }
}
public class AccountViewModel
{
public UserViewModel Account { get; set; }
}
and then your controller action will simply take the view model as parameter. In this case yo udon't need to decorate it with the [FromBody] attribute because by convention in Web API the default model binder will attempt to bind complex types from the body of the request:
public class AccountsController : ApiController
{
public HttpResponseMessage Post(AccountViewModel model)
{
// work with the model here and return some response
return Request.CreateResponse(HttpStatusCode.OK);
}
}
Also notice that since HTTP is a request/response protocol it makes much more sense to have your Web API controller actions return response messages as shown in my example rather than just having some void methods. This makes the code more readable. You immediately understand how the server will respond and with what status code to the specified request.