I have a fairly simple API that, when hitting one of the endpoints, gives me the following stack trace
Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches:
VimTube.Controllers.CategoryController.GetAllCategories (VimTube) VimTube.Controllers.CategoryController.GetCategoryByName (VimTube)
I understand that it is failing because I have two methods that point to the same URL. The same are the following
[HttpGet]
public Task<ActionResult<IEnumerable<Category>>> GetAllCategories()
{
return _repository.FindAll();
}
[HttpGet]
public IEnumerable<Category> GetCategoryByName([FromQuery]string name)
{
return _repository.ListCategoriesWhichStartsWith(name);
}
And my controller class is prefixed with vimtube/categories .
My idea would be to have these url's
- vimtube/categories returns a list of all categories.
- vimtube/categories?name=Ent returns the categories that start with the query you passed to it.
I read that with [FromQuery] this was possible, but apparently it is not. Thank you!