Copied to clipboard

Flag this post as spam?

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


  • Warren Buckley 2106 posts 4836 karma points MVP 8x admin c-trib
    Jan 28, 2014 @ 12:18
    Warren Buckley
    0

    Using Umbraco.Sys.ServerVariables for WebAPI Route URLs

    Hello,
    I have seen this post on the Umbraco.com site
    https://umbraco.com/follow-us/blog-archive/2014/1/17/heads-up,-breaking-change-coming-in-702-and-62.aspx

    And it mentions about using Umbraco.Sys.ServerVariables as a way to deliver the WebAPI Route URLs down to my JS for my AngularJS $http.get() calls.

    So if anyone has any examples on how to use this, that would be fantastic.

    Cheers,
    Warren :)

  • Shannon Deminick 1530 posts 5278 karma points MVP 4x
    Jan 28, 2014 @ 13:05
  • Shannon Deminick 1530 posts 5278 karma points MVP 4x
    Jan 28, 2014 @ 13:07
    Shannon Deminick
    1

    Warren it's also worth mentioning more about the umbRequestHelper which wraps the $http promises and does proper error checking on results such as overlaying the ysod display when in debug mode if your request throws a 500 result.

    for example when we call a service URL we might use:

    return umbRequestHelper.resourcePromise(
        $http.post(umbRequestHelper.getApiUrl("contentApiBaseUrl", "PostSort"),
            {
                parentId: args.parentId,
                idSortOrder: args.sortedIds
            }),
        'Failed to sort content');
    

    There's documentation about it too:

    http://umbraco.github.io/Belle/#/tutorials/using-promises-resources http://umbraco.github.io/Belle/#/api/umbraco.services.umbRequestHelper

  • Warren Buckley 2106 posts 4836 karma points MVP 8x admin c-trib
    Jan 28, 2014 @ 13:44
    Warren Buckley
    0

    Hi Shannon,
    Trying to get the example in the docs running but not having much luck.

    So on my ApplicationStarted event I have

    //Umbraco JS Server Variables - To Register WebAPI Route URLs
    ServerVariablesParser.Parsing = Parsing;
    

    And the associated void to add the example keys on the docs

    private void Parsing(object sender, Dictionary<string, object> dictionary)
    {
        //add stuff to the dictionary, preferably under your own custom section such as:
        dictionary.Add("myPackage", new Dictionary<string, object>
        {
            {"mySetting1", "blah"},
            {"mySetting2", "another value"}
        });
    }
    

    I have stepped through the Parsing void never seems to fire, so hence they keys never get added. I am running 7.0.2 from NuGet and I am not getting any build or compilation errors, so I am unsure what I am doing wrong.

    Thanks,
    Warren :)

  • Shannon Deminick 1530 posts 5278 karma points MVP 4x
    Jan 28, 2014 @ 23:28
    Shannon Deminick
    1

    Well, turns out there are 2 things wrong :( The first one is easy:

    You are not listing to the event properly, this is what you have:

    ServerVariablesParser.Parsing = Parsing;
    

    You need this:

    ServerVariablesParser.Parsing += Parsing;
    

    The second one is that it shouldn't let you have done that in the first place! And that is my fault, turns out I forgot to add the actual 'event' keyword to this delegate... lol, that's really dumb on my part!

    I'll fix that up for 7.0.3 but I think just adding the + in your code might actually work, which is very strange since it's actually not declared as an event in c# :P

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 17, 2014 @ 09:27
    David Brendel
    1

    So one question for this: Wanted to try it but the Url.GetUmbracoApiServiceBaseUrl isn't found at all. Which using statement do i need when i want to use that method when the applications starts to register my urls to the servervariables?

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 17, 2014 @ 16:30
    David Brendel
    1

    Ok found it. You need the Umbraco.Web Namespace

  • Warren Buckley 2106 posts 4836 karma points MVP 8x admin c-trib
    Jun 23, 2014 @ 17:00
    Warren Buckley
    1

    For my own reference & for anyone else coming across this thread I have typed up a blog post on why you want to use this & bhow easy it is to do:

    http://creativewebspecialist.co.uk/2014/06/23/what-on-earth-is-umbraco-servervariables-parsing/

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies