at first I had ordinary GET/POST/PUT/DELETE requests to my server, and this config.route of my web api was enough:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
then, I needed a custom action (for example, instead of api/User/212 - GET, I want to api/GetAllUsers - GET)
so I changed the config to that:
config.Routes.MapHttpRoute(
name: "DefaultApiWithAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "get" ,id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiGet",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "get", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiPost",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "post", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiPut",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "put", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApiDelete",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { action = "delete", id = RouteParameter.Optional }
);
the problem now, is that I can't reach the classic GET ('DefaultApiGet).
EDIT
In another words, if I have a user that I want to get his one post, or all posts then I want to be able to do that (user id = 12345): 'api/UserPost/12345' - get last post of user 12345 and 'api/UserPost/GetAll/12345' - get all posts of user 12345