user5283666
user5283666

Reputation:

Why does my rest-like routing not work?

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

Answers (1)

alsami
alsami

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

Related Questions