I am using Web API to expose a bunch of services. I am having issue with some routes and need some help.
I have the default route defined:
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new {id = RouteParameter.Optional} );
With this route I can hit normal routes such as: '/api/clients/' and '/api/clients/4'. I would like a GET that hits the following routes 'api/clients/4/profiles' and 'api/clients/4/validations'.
I have tried the following routes without success:
config.Routes.MapHttpRoute( name: "ClientProfilesApi", routeTemplate: "api/{controller}/{clientid}/profiles", defaults: new { action = RouteParameter.Optional }, constraints: new { controller = "clients" } ); config.Routes.MapHttpRoute( name: "ClientValidationsApi", routeTemplate: "api/{controller}/{clientid}/validations", defaults: new { action = RouteParameter.Optional }, constraints: new { controller = "clients" } );
I also tried using the 'ActionName' attribute as follows:
[HttpGet] [ActionName("profiles")] public IEnumerableResponseDto<ProfileLayoutDto> GetProfiles(Int64 clientId, [FromUri] IEnumerableRequestDto request) { .... } [HttpGet] [ActionName("profiles")] public IEnumerableResponseDto<ValidationLayoutDto> GetValidations(Int64 clientId, [FromUri] IEnumerableRequestDto request) { .... }
What am I missing? Is it not possible to have multiple GETs in a controller?