Looking at the examples and the docs, rather than hard code links to API URLs, you're meant to use umbRequestHelper.getApiUrl to get the route to your URLs, however, I cannot get it to work.
In Razor, I can call: Url.GetUmbracoApiService("GetAll", "PersonApi", "PluginName") to get the route. However, the client side method doesn't let you specify a plugin controller according to the docs, so how are you supposed to get the URL?
If I call umbRequestHelper.getApiUrl("PersonApi", "GetAll"); I get an error stating that no API URL can be found.
So what am I doing wrong? I can't find any specific examples of this in the docs.......
Also note that umbRequestHelper.getApiUrl will only work for entries put into the server vars dictionary: Umbraco.Sys.ServerVariables.umbracoUrls (as noted in the doc)
You can of course put your own keys into server vars and you don't need to use umbRequestHelper.getApiUrl which is just a wrapper. My advice is to not pollute the umbracoUrls and create your own dictionary entry for your own package like:
Thanks Shannon! I'll have a look at that now :) I was thinking that the getApiUrl method would return everything that was registered as an API controller automatically.
We were gonna do something like that, just didn't get around to it yet :)
We can't put all based UmbracoApiController urls in there since many of them would be for the front-end and we only care about the back office. We also want to keep the payload request (server variables) smaller and were thinking of changing this entirely to not include all base urls but just one, or something along those lines. Another idea could be to attribute a back office controller to ensure it gets put into the umbracoUrls server vars.
In any case, it's something we've thought about but haven't had time to look into the most ideal way to handle it. Sometime soon hopefully:)
How to use umbRequestHelper.getApiUrl
Looking at the examples and the docs, rather than hard code links to API URLs, you're meant to use umbRequestHelper.getApiUrl to get the route to your URLs, however, I cannot get it to work.
In Razor, I can call: Url.GetUmbracoApiService("GetAll", "PersonApi", "PluginName") to get the route. However, the client side method doesn't let you specify a plugin controller according to the docs, so how are you supposed to get the URL?
If I call umbRequestHelper.getApiUrl("PersonApi", "GetAll"); I get an error stating that no API URL can be found.
So what am I doing wrong? I can't find any specific examples of this in the docs.......
You need to create your own ServerVariables entry.
See: http://our.umbraco.org/documentation/Extending-Umbraco/version7-assets
Also note that umbRequestHelper.getApiUrl will only work for entries put into the server vars dictionary: Umbraco.Sys.ServerVariables.umbracoUrls (as noted in the doc)
You can of course put your own keys into server vars and you don't need to use umbRequestHelper.getApiUrl which is just a wrapper. My advice is to not pollute the umbracoUrls and create your own dictionary entry for your own package like:
Umbraco.Sys.ServerVariables.myPackage.myControllerBaseUrl
Thanks Shannon! I'll have a look at that now :) I was thinking that the getApiUrl method would return everything that was registered as an API controller automatically.
:)
Cheers,
Tim.
We were gonna do something like that, just didn't get around to it yet :)
We can't put all based UmbracoApiController urls in there since many of them would be for the front-end and we only care about the back office. We also want to keep the payload request (server variables) smaller and were thinking of changing this entirely to not include all base urls but just one, or something along those lines. Another idea could be to attribute a back office controller to ensure it gets put into the umbracoUrls server vars.
In any case, it's something we've thought about but haven't had time to look into the most ideal way to handle it. Sometime soon hopefully:)
is working on a reply...