Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    May 20, 2014 @ 00:58
    Tim
    0

    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.......

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    May 20, 2014 @ 02:07
    Shannon Deminick
    100

    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

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    May 20, 2014 @ 13:56
    Tim
    0

    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.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    May 21, 2014 @ 07:42
    Shannon Deminick
    0

    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:)

Please Sign in or register to post replies

Write your reply to:

Draft