My Controller:
[Route("Categories")]
[ApiController]
public class CategoriesController : ControllerBase
{
[HttpGet]
[Route("My")]
public string[] My()
{
return new[]
{
"Is the Microwave working?",
"Where can i pick the washing machine from?",
};
}
}
My startup.cs Configure():
app.UseMvc(routes =>
{
routes.MapRoute(name: "api", template: "api/v1/{controller}/{action}/");
});
This works only if I hit url "https://localhost:44325/categories/my"
I need it to have "https://localhost:44325/api/v1/categories/my".
What should I set differently?
I tried something like [Route("[api]/Categories")] attribute on the controller to compose the desired route, but it did not work...
I got:
The following errors occurred with attribute routing information:
Error 1: For action: 'historyAccounts.WebApi.Controllers.CategoriesController.My (historyAccounts.WebApi)' Error: While processing template '[api]/Categories/My', a replacement value for the token 'api' could not be found. Available tokens: 'action, controller'. To use a '[' or ']' as a literal string in a route or within a constraint, use '[[' or ']]' instead.