I am creating a web api that has multiple get / post calls that have the same signature. Now I know that in the case of several identical calls, you usually have 2 options: separate for different controllers or using {action} in your routes. I moved on to the {action} method, as it works best for most of my controllers. However, in one of my controllers, I would prefer not to use an action method.
I have a call like this:
[HttpGet] public Program Program(string venue, string eventId)
Now i need a new challenge
[HttpGet] public Program ProgramStartTime(string venue, string eventId)
I know that I can add an action name to it and call ie
api/{controller}/{action}/{venue}/{eventId}
But I feel that this is breaking the expected. Is there a way that I could be something like
api/Content/LAA/1/PST api/Content/LAA/1?PST
Also, if I need to go the route of actions, I already have a route that I use for other controllers, but it just uses {id} as the only parameter. Will the new route contradict this? Is there a better way to configure my routes?
config.Routes.MapHttpRoute( name: "...", routeTemplate: "api/{controller}/{action}/{id}", defaults: new {id = RouteParameter.Optional} ); config.Routes.MapHttpRoute( name: "...", routeTemplate: "api/{controller}/{action}/{venue}/{eventId}/{...}/{***}/{###}", defaults: new {### = RouteParameter.Optional} ); config.Routes.MapHttpRoute( name: "...", routeTemplate: "api/{controller}/{action}/{venue}/{eventId}/{...}", defaults: new {... = RouteParameter.Optional} ); config.Routes.MapHttpRoute( name: "...", routeTemplate: "api/{controller}/{action}/{venue}", defaults: new {venue = RouteParameter.Optional} );
I expect at least one method that would have up to 5 parameters