We can also create custom action selector for Api Controllers as follows, so that that can freely work with complex types with traditional "GET,POST,PUT,DELETE":
class ApiActionSelector : IHttpActionSelector
{
private readonly IHttpActionSelector defaultSelector;
public ApiActionSelector(IHttpActionSelector defaultSelector)
{
this.defaultSelector = defaultSelector;
}
public ILookup<string, HttpActionDescriptor> GetActionMapping(HttpControllerDescriptor controllerDescriptor)
{
return defaultSelector.GetActionMapping(controllerDescriptor);
}
public HttpActionDescriptor SelectAction(HttpControllerContext controllerContext)
{
// Get HttpMethod from current context
HttpMethod httpMethod = controllerContext.Request.Method;
// Set route values for API
controllerContext.RouteData.Values.Add("action", httpMethod.Method);
// Invoke Action
return defaultSelector.SelectAction(controllerContext);
}
}
And we can register the same in WebApiConfig as :
config.Services.Replace(typeof(IHttpActionSelector), new
ApiActionSelector(config.Services.GetActionSelector()));
May help users who are running this kind of issue.