I am looking for a solution to the same problem. I am currently testing this solution.
First of all, change the route:
routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}/{action}/{id2}", defaults: new { id = RouteParameter.Optional, action = "Index", id2 = RouteParameter.Optional } );
Then, if you want SellersController
, write it as usual, but name the entire action "Index" and use the notation to correctly route the http verb. For instance:
[HttpGet] public List<Seller> Index() {}
Then, in SellersController
create actions, naming them as your "internal" object ( Products
).
[HttpGet] public List<Product> Products(int id) {} [HttpGet] public Product Products(int id, int id2) {}
So you can call
GET /api/sellers or GET /api/sellers/99/products or GET /api/sellers/99/products/2
I am really testing this approach, so any feedback would be appreciated!
source share