So I have the basic Hello World service running in DNN 6.2 Services Framework, which is based on MVC. The route, taken from example, is:
routeManager.MapRoute("MyServices", "{controller}/{action}", new[] { "HelloWorldServices" });
When my action go to ~/DesktopModules/MyServices/API/Welcome/HelloWorld, it calls the HelloWorld function and works. So far, I've managed to figure out that I can do this:
routeManager.MapRoute("MyServices", "{controller}/{action}/{userID}", new[] { "HelloWorldServices" });
When I go to ~/DesktopModules/MyServices/API/Welcome/users, it calls the users function, which has an optional parameter for the ID, and that is working. But now I want to make an endpoint ~/DesktopModules/MyServices/API/Welcome/locations, which could take a location ID. I can't just write this:
routeManager.MapRoute("MyServices", "{controller}/{action}/{locationID}", new[] { "HelloWorldServices" });
or even
routeManager.MapRoute("MyServices", "{controller}/locations/{locationID}", new[] { "HelloWorldServices" });
It doesn't work that way. Whichever is first (users or locations) recognizes the ID and whichever is second does not. While I can figure out what does not work, I have no idea what will work, and have not been able to find out despite a lot of searching. I also found some examples that look like this:
routeManager.MapRoute("Html", "default", "", new { controller = "Service", action = "GetTabs" }, new[] { "DotNetNuke.Modules.Html" });
But I can't figure out how that works, either. Eventually I'll want to do "~/DesktopModules/MyServices/API/Welcome/users/userid/locations/" as well. If anyone could give me some examples, that would be much appreciated!
UPDATE: Based on the answer I looked up MVC routing. I realized I had to write it generically, and now have these working:
{controller}/{action}
{controller}/{action}/{id}
{controller}/{action}/{id}/{secondaction}
{controller}/{action}/{id}/{secondaction}/{secondid}
"id", "secondaction", and "secondid" are all optional string parameters. So I can have "users/userid/locations/locationid"... the "locations/locationid" part is handled in the "users" function.