JSONP Web Service

Table of contents

Endpoint

Send your requests to the following URL :

http://api.routeyou.com/<version>/json/<service>/<token>

Replace the pieces between < and > with :

Construct a JSONP Request

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

JSONP Response

The server sends back a piece of Javascript code. That Javascript code calls your callback function with 2 parameters :

Example:

Fetch all the routes (private ones included) you have marked as favourite:

/*
 * Start session. Acquire the token that is needed for following web service calls
 */
$params = array(
    '<key>'
);
$url = 'http://api.routeyou.com/2.0/json/Session?id=1&method=start&params=' .
    json_encode($params);
$result = file_get_contents($url);
$result = json_decode($result, true);
$token = $result['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);
$result = file_get_contents($url);
$result = json_decode($result, true);
$user = $result['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);
$content = file_get_contents($url);
$result = json_decode($content, true);
var_dump($result['result']);

© 2006-2014 RouteYou - www.routeyou.com