Page 1 of 1

How to specify endpoint address in JavaScript?

Posted: Mon Mar 15, 2021 11:46 am
by Bernd Welter
Hi there,
maybe a simple question but: how to set the target URL of our JavaScript clients properly?
Usecase: as a Developer I want to develop a client application against a test environment and then within the deployment I want to change the endpoint address. But how to assign this properly?

Bernd

PS: here are some incomplete examples - the missing link is probably just a single statement. But which one?
  • The following code is taken from our documentation and tells me how to set the credentials.

    Code: Select all

    var xroute = new XRouteClient("https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/");
    xroute.setCredentials('xtok', '<your xserver-internet token>');
  • In the integration samples the code looks like this - it is based on "the client class already knows the endpoint address":

    Code: Select all

    var A = {
        "$type": "OffRoadWaypoint",
        "location": {
            "offRoadCoordinate": {
                "x": 6.1256572,
                "y": 49.5983745
            }
        }
    };
    
    var B = {
        "$type": "OnRoadWaypoint",
        "location": {
            "coordinate": {
                "x": 6.1256572,
                "y": 49.4816576
            }
        }
    };
    
    xroute.calculateRoute({
        "waypoints": [A, B]
    }, routingCompleted);
    
    function routingCompleted(route, exception) {
        print(route.distance + 'm in ' + route.travelTime + 's');
    }

Re: How to specify endpoint address in JavaScript?

Posted: Mon Mar 15, 2021 12:50 pm
by Joost
IIRC:

Code: Select all

var xroute = new XRouteClient("https://xserver2-europe-eu-test.cloud.ptvgroup.com/services/rs/XRoute/")