I am developing a API using OWINHost and in my controller i've got an post method that is expecting a Json. If the Json is structured properly, everything is working just fine, but i am not being able to throw an error if the structure is different.
I thougth about instead of receive a type "SMS" as an parameter, receives a string then use Newtonsoft.Json to parse that string, if it parses incorrectly throw the error, but i am not sure if this is good pracctice.
[HttpPost]
public HttpResponseMessage NewMessage(HttpRequestMessage request, [FromBody] SMS sms)
{
// some code
//return Ok if everything runs smoothly
return request.CreateResponse(HttpStatusCode.OK);
}
I need to know when the structure of the json is incorrect so i can throw an error status.
{
"Number": "12345",
"Content": "Test"
}
This is the json structure, and this is my SMS class
public class SMS
{
public string Number{ get; set; }
public string Content{ get; set; }
}