I am trying to create a web app that will receive HTTP Posts containing json. All I want to do for now is show that I can receive the requests. I started by creating an ASP .NET web app with Web API template. I added a controller to receive the posts:
public class PostmanController : Controller
{
[System.Web.Mvc.HttpPost]
public void Index([FromBody] string request)
{
// Create handler class object
PostmanHandler test = new PostmanHandler();
// Pass request to the convertjsontoobject method
test.ConvertJsonToObject(request);
}
}
As you can see here, I also created a handler in the Models folder:
public class PostmanHandler
{
public void ConvertJsonToObject(string s)
{
// Deserialize JSON
var newData = JsonConvert.DeserializeObject<testobject>(s);
}
}
Which converts the JSON into a class I made:
public class testobject
{
public int id { get; set; }
public string name { get; set; }
}
I am trying to test this out to see if it works but I get a 404 response from Postman when I send a POST request. I am sending it to http://localhost:xxxx/api/Postman which I thought follows the routing in the WebApiConfig file that states: routeTemplate: "api/{controller}/{id}"
Am I leaving out some sort of routing?