Advertisement

JSONP web service

Table of contents

Endpoint

Send requests to the following URL:

https://api.routeyou.com/%service-version%/json/%service-name%/%token%

The parts between % should be replaced with the following:

Construct request

A JSONP request is sent using HTTP GET, with these URL parameters:

Keep in mind that most browsers have a limit on URL length, passing large amounts of data to the web service may not be possible with this protocol (it is not a problem for the response).

Response

The server sends back a JSON encoded object containing these keys:

If you have provided the callback parameter in the request, your callback function is called with the response.

Example (PHP)

The following code fetches all the routes (private ones included) you have marked as favorite. Note that there is no error handling in this example.

// Start session. Acquire the token that is needed for the subsequent web service calls.
$params = array(
    '<key>'
);
$url = 'https://api.routeyou.com/2.0/json/Session?id=1&method=start&params=' .
    json_encode($params);
$response = json_decode(file_get_contents($url), true);
$token = $response['result'];

// Log in.
$params = array(
    '<email>',
    '<password>'
);
$url = 'https://api.routeyou.com/2.0/json/User/' . $token .
    '?id=1&method=loginWithEmail&params=' . json_encode($params);
$response = json_decode(file_get_contents($url), true);
$user = $response['result'];

// Fetch favourite routes.
// When parameter permission.readable is omitted, only public routes are returned.
$params = array(
    array(
        'favorite.user.id' => $user['id'],
        'permission.readable' => true
    )
);
$url = 'https://api.routeyou.com/2.0/json/Route/' . $token .
    '?id=1&method=search&params=' . json_encode($params);
$response = json_decode(file_get_contents($url), true);
$favorites = $response['result'];
var_dump($favorites);

Back to RouteYou

© 2006-2024 RouteYou - www.routeyou.com