Beispiel #1
0
$version = floor(file_get_contents(__DIR__ . '/VERSION'));
if ($matches && isset($matches[1]) && $matches[1] == 2) {
    $version = 2;
}
// Do not put .json at the end of the resource
Resources::$useFormatAsExtension = false;
//Do not hide the API
Resources::$hideProtected = false;
// Use /api/v1/projects uri
Defaults::$useUrlBasedVersioning = true;
if (ForgeConfig::get('DEBUG_MODE')) {
    $restler = new Restler(false, true);
} else {
    $restler = new Restler();
}
$restler->setAPIVersion($version);
$restler->setSupportedFormats('JsonFormat', 'XmlFormat');
$core_resources_injector = new Tuleap\REST\ResourcesInjector();
$core_resources_injector->populate($restler);
switch ($version) {
    case 2:
        $event = Event::REST_RESOURCES_V2;
        break;
    default:
        $event = Event::REST_RESOURCES;
        break;
}
EventManager::instance()->processEvent($event, array('restler' => $restler));
$restler->addAPIClass('Resources');
$restler->addAuthenticationClass('\\Tuleap\\REST\\TokenAuthentication');
$restler->addAuthenticationClass('\\Tuleap\\REST\\BasicAuthentication');
Beispiel #2
0
Example 3: GET v2/bmi?height=190 returns
{
  "error": {
    "code": 400,
    "message": "Bad Request: invalid height unit"
  }
}
Example 4: GET v2/bmi?height=162cm returns
{
  "bmi": 23.27,
  "message": "Normal weight",
  "metric": {
    "height": "190 centimeters",
    "weight": "84 kilograms"
  },
  "imperial": {
    "height": "6 feet 2 inches",
    "weight": "185.19 pounds"
  }
}
Content:
*/
require_once '../../../vendor/restler.php';
use Luracast\Restler\Defaults;
use Luracast\Restler\Restler;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->setAPIVersion(2);
$r->addAPIClass('BMI');
$r->addAPIClass('Explorer');
$r->handle();