Reputation:
I am building a web API in .net core 2.1 in which I want to have rest-like routing for some entities, like below. But whatever I Try I cannot get this routing to work. Any ideas what Im doing wrong?
In this query I want to hit the endpoint http://localhost:5000/api/ContactGroup/1/persons to get all persons belonging to a contactgroup with ID 1.
[HttpPost("{groupId}/persons", Name ="GetContactGroupPersons")]
public async Task<ActionResult>GetContactGroupPersons(int groupId)
{
var returnObject = _manager.GetData(groupId);
return Ok(returnObject);
}
Result from query is 404, not found::
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5000/api/ContactGroup/1/persons
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 4.2288ms 404
Upvotes: 0
Views: 38
Reputation: 9815
Your method is marked as [HttpPost]
but you are issuing a GET. Just change it to that
[HttpGet("{groupId}/persons", Name ="GetContactGroupPersons")]
Upvotes: 1