Luracast/Restler — Issue #23: API Versioning with Restler v2.x
Author: RVN-BR
Created: 2011-12-21 01:04:38+00:00
State: open

A couple of people talked about versioning so I thought i'd add my way of doing it so far. It has worked great and no issues that I have come accross. please do give feedback and let me know if you have any suggestions for improvement:

basic structure:

WEBROOT/
WEBROOT/API/
WEBROOT/API/lib/ (all restler files here, shared for any version of API)
WEBROOT/API/index.php (main router)
WEBROOT/API/v1/* (all files for version 1)
WEBROOT/API/v2/* (etc, for version 2)

Note: each version directory includes its own "routes" file. Otherwise I was unable to add/remove functions from one version to the next of the API.

Example index.php:

setSupportedFormats('JsonFormat', 'XmlFormat');

require_once 'routes.php';

$r->addAuthenticationClass('Authentication');

$r->handle();
?>

And now for routes.php (repeat this file inside each application version directory:

addAPIClass('someroute',$Version.'someroute');
$r->addAPIClass('teste',$Version.'teste'); // BEWARE TO HAVE EXACTLY THE SAME NAMES IN BOTH... dont mix upper/lower, etc.. make it identical! An idea may be to use an array, but I just make sure when I add the routes... (an array and a foreach to addapiclass using the same array element so it is passed exactly the same).
?>

I hope this is of use to someone... just wanted to give a bit back ;)