I'm struggling to work out the routing configuration needed to support the following simple scenario:
http..service/api/objects/key1/key2
I feel like I've tried everything.
The biggest problem is that whenever it looks like I've cracked it, I find that
http..service/api/objects/key1
gets routed to the parameterless IQueryable Get.
I think I've nailed it.
routes.MapHttpRoute(
name: IQueryableObjectsApiRouteName,
routeTemplate: "api/objects",
defaults: new { controller = "objects" }
);
routes.MapHttpRoute(
name: ObjectsApiRouteName,
routeTemplate: "api/objects/{siteId}/{assetId}",
defaults: new { controller = "objects", siteId = "", assetId = "" }
);
I need to setup two explicit routes to each controller with composite keys. The default values for the keys are "", which I detect in the controller and throw my own 404.
It works for me. I can go to lunch now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With