I am trying to make hierarchical link in my RESTapi. For example:
Following url will give me details of actor id 1:
/api/v1/actor/id/1/
Following url is expected to give me all movies of actor id 1:
/api/v1/actor/1/movies
My routes:
config.Routes.MapHttpRoute(
name: "DefaultCAApi",
routeTemplate: "api/v1/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultOneLevelNested",
routeTemplate: "api/v1/{controller}/{levelOneId}/{action}",
defaults: new { id = RouteParameter.Optional }
);
My Actions in ActorController
:
[HttpGet]
public HttpResponseMessage Id(int id)
{
// logic
return Request.CreateResponse(HttpStatusCode.OK, actor);
}
[HttpGet]
public HttpResponseMessage Movies(int levelOneId)
{
// logic
return Request.CreateResponse(HttpStatusCode.OK, movies);
}
But this setup is not working for me.
/api/v1/actor/id/1/
gives me proper response
But /api/v1/actor/1/movies
is throwing following error:
No action was found on the controller 'Actor' that matches the name '1'."
I did follow this thread, but it did not work for me.
Can some please suggest what wrong I am doing here? I am using MVC 4, WebAPI.