API
[RoutePrefix("api/diagnostics")]
public class DiagnosticsController : ApiController
{
[HttpPost]
[Route("pings")]
public IHttpActionResult Pings(Ping ping)
{
}
}
Ping
public class Ping
{
public Guid ServerKey {get;set;}
public DateTime CreatedDateTime {get;set;}
}
I am trying to test the class using Postman application. Here is the Screenshot.
The message I get back is:
{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:61668/api/diagnostics/pings'.",
"messageDetail": "No action was found on the controller 'Diagnostics' that matches the request."
}
I am failing to understand why it does not match the post action in Diagnostics controller. The only other route configured is the default route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{key}",
defaults: new { key = RouteParameter.Optional }
);
Also attribute routing is enabled: config.MapHttpAttributeRoutes();
Ping
object? Consider using nullable values rather than Guid/DateTime. Can you create a new project with these classes as a bare minimum and does it work then?