I need to make a ASP.NET Core, Web API
that supports multiple HttpGet
verbs with the only difference being a query string, but it seems that query strings cannot be part of the route template -- is that true?
The route templates are very similar, in fact they only differ by query string.
[Authorize]
public class SymbolsController : Controller
{
[
HttpGet,
Route("api/symbols")
]
public Task<IEnumerable<Symbol>> Symbols([FromServices] ISymbolService symbolService)
{
return symbolService.GetSymbolsAsync();
}
[
HttpGet,
Route("api/symbols?{childrenOf=id}")
]
public Task<IEnumerable<Symbol>> ValidChildren(
[FromQuery] Guid id,
[FromServices] ISymbolService symbolService)
{
return symbolService.GetValidChildrenAsync(id);
}
}
This throws an exception as the ?
is not a valid character in the route template. How can I achieve this?