JSONP web service

Table of contents

Endpoint

Send requests to the following URL:

http://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 favourite. 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 = 'http://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 = 'http://api.routeyou.com/1.1/json/Authentication/' . $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(
        'favourite.user.id' => $user['id'],
        'permission.readable' => true
    )
);
$url = 'http://api.routeyou.com/2.0/json/Route/' . $token .
    '?id=1&method=search&params=' . json_encode($params);
$response = json_decode(file_get_contents($url), true);
$favourites = $response['result'];
var_dump($favourites);

© 2006-2015 RouteYou - www.routeyou.com