public function populate(Restler $restler) { $restler->addAPIClass('\\Tuleap\\Project\\REST\\ProjectResource', ProjectRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\Token\\REST\\TokenResource', TokenRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\Project\\REST\\UserGroupResource', UserGroupRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\User\\REST\\UserResource', UserRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\User\\REST\\v1\\UserMembershipResource', UserMembershipRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\PhpWiki\\REST\\v1\\PhpWikiResource', PhpWikiPageRepresentation::ROUTE); $restler->addAPIClass('\\Tuleap\\JWT\\REST\\v1\\JWTResource', JWTRepresentation::ROUTE); }
<metric> <height>162.6 centimeter</height> <weight>84 kilograms</weight> </metric> <imperial> <height>5 feet 4 inches</height> <weight>185.19 pounds</weight> </imperial> </response> Example 3: GET bmi.json returns { "bmi": 31.77, "message": "Obesity", "metric": { "height": "162.6 centimeter", "weight": "84 kilograms" }, "imperial": { "height": "5 feet 4 inches", "weight": "185.19 pounds" } } */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->setSupportedFormats('JsonFormat', 'XmlFormat'); $r->addAPIClass('BMI'); $r->handle();
3. Add `@access protected` comment to the class to protect all methods of that class In order to provide access to those protected methods we use a class that implements `iAuthenticate`. Also note that An Authentication class is also an API class so all public methods that does not begin with `_` will be exposed as API for example [SimpleAuth::key](simpleauth/key). It can be used to create login/logout methods. Example 1: GET restricted returns { "error": { "code": 401, "message": "Unauthorized" } } Example 2: GET restricted?key=rEsTlEr2 returns "protected method" Example 3: GET secured?key=rEsTlEr2 returns "protected class" */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Simple', ''); //map it to root $r->addAPIClass('Secured'); $r->addAuthenticationClass('SimpleAuth'); $r->handle();
<?php /* * Testing all the attributes for @param annotation */ use Luracast\Restler\Restler; use Luracast\Restler\Defaults; require_once "../../../vendor/restler.php"; Defaults::$crossOriginResourceSharing = true; $r = new Restler(); $r->addAPIClass('MinMax'); $r->addAPIClass('MinMaxFix'); $r->addAPIClass('Type'); $r->addAPIClass('Validation'); //$r->addAPIClass('Resources'); $r->addAPIClass('Explorer', 'swagger'); $r->handle();
} preg_match('/^\\/api\\/v(\\d+)\\//', $_SERVER['REQUEST_URI'], $matches); $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');
> **Note:-** > > 1. Using session variables as DB and Cache is useless for real life and wrong. We are using it > Only for demo purpose. Since API Explorer is browser based it works well with that. > > 2. We are using Author.php to document return type of `GET authors/{id}` using `@return` comment If you have hit the API Rate Limit or screwed up the Authors DB, you can easily reset by deleting PHP_SESSION cookie using the Developer Tools in your browser. Helpers: Author Footer: *[Author.php]: _009_rate_limiting/Author.php */ use Luracast\Restler\Defaults; use Luracast\Restler\Filter\RateLimit; use Luracast\Restler\Restler; require_once '../../../vendor/restler.php'; //reuse the SessionDB from CRUD Example require_once '../_007_crud/DB/Session.php'; //used only for demo, comment the following line Defaults::$cacheClass = 'SessionCache'; //set extreme value for quick testing RateLimit::setLimit('hour', 10); $r = new Restler(); $r->addAPIClass('ratelimited\\Authors'); $r->addAPIClass('Resources'); $r->addFilterClass('RateLimit'); $r->addAuthenticationClass('KeyAuth'); $r->handle();
@view folder/name.extension When the extension is omitted `HtmlFormat::$format` will be used HtmlFormat will look at `views` folder that resides parallel to `vendor` directory for the template files and can be changed by setting `HtmlFormat::$viewPath` to full path of a folder Content: In this example, we are building tasks api and also a single page application using jQuery and the templates [![Single Page App](../resources/html_view.png)](tasks) Our api response is sent to the template under the name `response` along with other information such as `basePath`, `baseUrl`, `request` parameters. You can send custom data yourself by setting key value pairs in `HtmlFormat::$data` array If you do not want all the information and want to keep your template simple, you can use `{@data key.innerkey}` comment as shown below @view todo/list {@data response} This calls the list template with key value pairs defined at the response array directly accessible as the variable and value inside the template This example also show cases the heredoc syntax based simple templating system which is Supported with out any external dependencies Just to show that it is possible to come up with API as well as an App using the same resource and url, you can try the json version of the tasks api using the API Explorer [here](explorer/index.html) */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->setSupportedFormats('JsonFormat', 'HtmlFormat'); $r->addAPIClass('Tasks'); $r->addAPIClass('Resources'); $r->handle();
if ($matches && isset($matches[1]) && $matches[1] == 2) { $version = 2; } // Do not put .json at the end of the resource Explorer::$useFormatAsExtension = false; //Do not hide the API Explorer::$hideProtected = false; // Use /api/v1/projects uri Defaults::$useUrlBasedVersioning = true; if (ForgeConfig::get('DEBUG_MODE')) { $restler = new Restler(false, true); $restler->setSupportedFormats('JsonFormat', 'XmlFormat', 'HtmlFormat'); } else { $restler_cache = new RestlerCache(); Defaults::$cacheDirectory = $restler_cache->getAndInitiateCacheDirectory($version); $restler = new Restler(true, false); $restler->setSupportedFormats('JsonFormat', 'XmlFormat'); } // Do not let Restler find itself the domain, when behind a reverse proxy, it's // a mess. $restler->setBaseUrl($sys_default_domain); $restler->setAPIVersion($version); $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;
<?php use Luracast\Restler\Restler; require __DIR__ . '/../vendor/autoload.php'; $r = new Restler(); $r->addAPIClass('Home', ''); $r->addAPIClass('Explorer'); $r->handle();
<?php require_once 'vendor/restler.php'; require_once 'classes/Transaction.php'; use Luracast\Restler\Restler; //remove .json from urls of all service methods Resources::$placeFormatExtensionBeforeDynamicParts = false; $r = new Restler(); $r->refreshCache(); $r->setSupportedFormats('JsonFormat'); $r->addAPIClass('Transactionservice'); $r->addApiClass('Resources'); //this produces the needed resources.json $r->handle();
Cookie: PHPSESSID=dcdfec433e86c1a6730f75303187071f {"name":"Another","email":"*****@*****.**"} ``` and the response for all the above could be ```http HTTP/1.1 200 OK Date: Tue, 25 Sep 2012 10:05:06 GMT Server: Apache/2.2.19 (Unix) mod_ssl/2.2.19 OpenSSL/0.9.8r DAV/2 PHP/5.3.6 with Suhosin-Patch X-Powered-By: Luracast Restler v3.0.0 Expires: 0 Cache-Control: no-cache, must-revalidate Pragma: no-cache Content-Length: 66 Content-Type: application/json { "name": "Another", "email": "*****@*****.**", "id": 7 } ``` Helpers: DB\Session Content: *[MySQL.php]: _007_crud/DB/PDO/MySQL.php *[Sqlite.php]: _007_crud/DB/PDO/Sqlite.php *[SerializedFile.php]: _007_crud/DB/SerializedFile.php */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Authors'); $r->handle();
[Restler API Explorer](https://github.com/Luracast/Restler-API-Explorer) which is used [here](explorer/index.html#!/authors-v1). [![Restler API Explorer](../resources/explorer1.png)](explorer/index.html#!/authors-v1) We are progressively improving the Authors class from CRUD example to Rate Limiting Example to show Best Practices and Restler 3 Features. Make sure you compare them to understand. Even though API Explorer is created with API consumers in mind, it will help the API developer with routing information and commenting assistance when our API class is not fully commented as in this example. This works only on the debug mode. Try changing rester to run in production mode (`$r = new Restler(true)`) > **Note:-** production mode writes human readable cache file for the routes in > the cache directory by default. So make sure cache folder has necessary > write permission. Happy Exploring! :) */ require_once '../../../vendor/restler.php'; //reuse the SessionDB from CRUD Example require_once '../_007_crud/DB/Session.php'; use Luracast\Restler\Restler; $r = new Restler(); // comment the line above and uncomment the line below for production mode // $r = new Restler(true); $r->addAPIClass('improved\\Authors'); $r->addAPIClass('Resources'); $r->handle();
| Register The Auto Loader |-------------------------------------------------------------------------- | | Composer provides a convenient, automatically generated class loader | for our application. We just need to utilize it! We'll require it | into the script here so that we do not have to worry about the | loading of any our classes "manually". Feels great to relax. | */ require __DIR__ . '/../bootstrap/autoload.php'; /* |-------------------------------------------------------------------------- | Configure your Web Application |-------------------------------------------------------------------------- */ use Luracast\Restler\Restler; use Luracast\Restler\Format\HtmlFormat; $r = new Restler(true); $r->setSupportedFormats('JsonFormat', 'HtmlFormat'); $r->addApiClass('Explorer'); $r->addApiClass('Authors'); /* |-------------------------------------------------------------------------- | Run The Application |-------------------------------------------------------------------------- | | Once we have the application set up, we can simply let it handle the | request and response | */ $r->handle();
<?php error_reporting(0); header('Content-Type: application/json; charset=utf-8'); require 'vendor/autoload.php'; require 'PortalTransparencia.php'; use Luracast\Restler\Restler; $rest = new Restler(); $rest->addAPIClass('PortalTransparencia'); $rest->handle();
*/ require_once 'vendor/restler.php'; use Luracast\Restler\Restler; use Luracast\Restler\Responder; use Luracast\Restler\Defaults; /* * There was a need for more complex validation return messages. this showed the way: * http://stackoverflow.com/questions/13107318/how-can-i-return-a-data-object-when-throwing-a-restexception * In a nutshell, extend the Responder class (that restler uses for giving a structure to the error and success response) * like below: */ class MyResponder extends Responder { public static $data = null; public function formatError($statusCode, $message) { $r = array('error' => array('code' => $statusCode, 'message' => $message)); if (isset(self::$data)) { $r['data'] = self::$data; } return $r; } } Defaults::$responderClass = 'MyResponder'; require_once 'pbo/property.php'; // Restler setup. See the following for details: http://restler3.phpfogapp.com/examples/ $r = new Restler(); $r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root $r->addAPIClass('Property'); $r->handle();
<?php /* Title: Access Control Tagline: Who can do what Tags: access-control, acl, secure, authentication, authorization Requires: PHP >= 5.3 Description: This example shows how you can extend the authentication system to create a robust access control system. As a added bonus we also restrict api documentation based on the same. When the `api_key` is - blank you will see the public api - `12345` you will see the api that is accessible by an user - `67890` you will see all api as you have the admin rights Try it out yourself [here](explorer/index.html#!/v1) */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Access', ''); $r->addAPIClass('Resources'); $r->addAuthenticationClass('AccessControl'); $r->handle();
<?php require_once '../bootstrap.php'; require_once 'SimpleAuth.php'; use Luracast\Restler\Resources; Resources::$useFormatAsExtension = false; use Luracast\Restler\Restler; $r = new Restler(true, true); $r->addAPIClass('Luracast\\Restler\\Resources'); $r->setSupportedFormats('JsonFormat'); $r->addAuthenticationClass('SimpleAuth'); $r->addAPIClass('User'); $r->addAPIClass('Book'); $r->addAPIClass('Car'); $r->addAPIClass('Ads'); $r->addAPIClass('Clicks'); $r->addAPIClass('Points'); $r->addAPIClass('Plan'); $r->addAPIClass('Mvnos'); $r->addAPIClass('Subscribers'); $r->addAPIClass('Mvno'); $r->addAPIClass('Impression'); $r->handle();
Make sure you compare them to understand. Even though API Explorer is created with API consumers in mind, it will help the API developer with routing information and commenting assistance when our API class is not fully commented as in this example. This works only on the debug mode. Try changing rester to run in production mode (`$r = new Restler(true)`) > **Note:-** production mode writes human readable cache file for the routes in > the cache directory by default. So make sure cache folder has necessary > write permission. Happy Exploring! :) */ require_once 'vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); // comment the line above and uncomment the line below for production mode // $r = new Restler(true); $r->addAPIClass('generator\\Constructor'); $r->addAPIClass('generator\\Generator'); $r->addAPIClass('noob\\sycon\\Authentication'); $r->addAPIClass('noob\\sycon\\Bill'); $r->addAPIClass('noob\\sycon\\Cashier'); $r->addAPIClass('noob\\sycon\\Category'); $r->addAPIClass('noob\\sycon\\Client'); $r->addAPIClass('noob\\sycon\\CommandProduct'); $r->addAPIClass('noob\\sycon\\Commands'); $r->addAPIClass('noob\\sycon\\Customer'); $r->addAPIClass('noob\\sycon\\History'); $r->addAPIClass('noob\\sycon\\Lot'); $r->addAPIClass('noob\\sycon\\Measure');
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); $loader = (require_once 'restler/vendor/autoload.php'); $loader->setUseIncludePath(true); use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Say'); // repeat for more $r->addAPIClass('Check'); // repeat for more $r->handle(); //serve the response
###Authorization### The client apps role in authentication is two-fold. First it must direct the user to the server to start the process. And second, when the authorization has completed the client application's *callback* function will be executed and it will be responsible for saving the authorization information. ###Authentication### Once the proper authorization has been attained by the client app, it's sole responsibility is to pass along it's authorization status in each RESTful API request. This is achieved by the client application adding a *query parameter* of 'code' set to the access token that the OAuth Server provided to the application in the authorization step. > **Note:-** > there is an optional parameter on the server that allows the Access Token to be passed as a header variable instead of a > query parameter. ## In Conclusion ## The "client application" plays an important role in the OAuth interaction and while your Restler server's primarily role will likely be to play the *server* role in this process it is useful to know that both client and server are available as part of the [OAuth 2.0 Server ](http://bshaffer.github.io/oauth2-server-php-docs/) module and both are easily made available to Restler. For more information on how to start using this functionality with Restler be sure to look at the [OAuth Server example](../_015_oauth2_server/index.php). */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; use OAuth2\Client; //This client takes to the server in the next folder, you can change it by un commenting //Client::$serverUrl = 'http://brentertainment.com/oauth2/lockdin'; $r = new Restler(); $r->addAPIClass('OAuth2\\Client', ''); $r->setOverridingFormats('HtmlFormat', 'UploadFormat', 'JsonFormat'); $r->handle();
/** * Parses the inline php doc comments and embedded data. * * @param $subject * * @return array * @throws Exception */ private function parseEmbeddedData($subject) { $data = array(); //parse {@pattern } tags specially while (preg_match('|(?s-m)({@pattern (/.+/[imsxuADSUXJ]*)})|', $subject, $matches)) { $subject = str_replace($matches[0], '', $subject); $data['pattern'] = $matches[2]; } while (preg_match('/{@(\\w+)\\s?([^}]*)}/ms', $subject, $matches)) { $subject = str_replace($matches[0], '', $subject); if ($matches[2] == 'true' || $matches[2] == 'false') { $matches[2] = $matches[2] == 'true'; } elseif ($matches[2] == '') { $matches[2] = true; } if ($matches[1] == 'pattern') { throw new Exception('Inline pattern tag should follow {@pattern /REGEX_PATTERN_HERE/} format and can optionally include PCRE modifiers following the ending `/`'); } elseif (false !== strpos($matches[2], static::$arrayDelimiter)) { $matches[2] = explode(static::$arrayDelimiter, $matches[2]); } $data[$matches[1]] = $matches[2]; } while (preg_match(self::$embeddedDataPattern, $subject, $matches)) { $subject = str_replace($matches[0], '', $subject); $str = $matches[self::$embeddedDataIndex]; if (isset($this->restler) && self::$embeddedDataIndex > 1 && !empty($matches[1])) { $extension = $matches[1]; $formatMap = $this->restler->getFormatMap(); if (isset($formatMap[$extension])) { /** * @var \Luracast\Restler\Format\iFormat */ $format = $formatMap[$extension]; $format = new $format(); $data = $format->decode($str); } } else { // auto detect if ($str[0] == '{') { $d = json_decode($str, true); if (json_last_error() != JSON_ERROR_NONE) { throw new Exception('Error parsing embedded JSON data' . " {$str}"); } $data = $d + $data; } else { parse_str($str, $d); //clean up $d = array_filter($d); foreach ($d as $key => $val) { $kt = trim($key); if ($kt != $key) { unset($d[$key]); $key = $kt; $d[$key] = $val; } if (is_string($val)) { if ($val == 'true' || $val == 'false') { $d[$key] = $val == 'true' ? true : false; } else { $val = explode(self::$arrayDelimiter, $val); if (count($val) > 1) { $d[$key] = $val; } else { $d[$key] = preg_replace('/\\s+/msu', ' ', $d[$key]); } } } } $data = $d + $data; } } } return array($subject, $data); }
<?php require_once __DIR__ . '/../../../fw/includes.php'; require_once __DIR__ . '/../ExcelImport.php'; require_once __DIR__ . '/../../../api/vendor/restler.php'; use Luracast\Restler\Restler; use Luracast\Restler\Format\UploadFormat; $r = new Restler(); UploadFormat::$allowedMimeTypes = Config::get('allowedMimeTypes', 'excelImport'); $r->setSupportedFormats('JsonFormat', 'UploadFormat'); // some strange error in Restler when UploadFormat is mentioned as first parameter $r->addAPIClass('ExcelImportApi', ''); $r->handle();
public function __construct($productionMode = false, $refreshCache = false) { parent::__construct($productionMode, $refreshCache); }
@format HtmlFormat @view oauth2/server/authorize.twig The @view and @format comments above the `authorize` method will serve the date through right template(view) file out to the user. Following a user granting authorization, the server will use the client application's *callback* function to pass back an access token. ### Authentication ### For any Restler resources which require authentication, the OAuth server will use the 'code' *query parameter* and compare that to it's internal records to validate that the user has the appropriate permissions. > **Note:-** > there is an optional parameter on the server that allows the Access Token to be passed as a header variable instead of > a query parameter. ## In Conclusion ## Many people are experientially familiar with OAuth clients either as a user who has granted apps permissions or as a developer who has downloaded one of many OAuth clients to get at social data from sources like Twitter, Facebook, Foursquare, etc. The server side of the interaction is less familiar yet it needs to be the primary focus for any RESTful API that imagines itself as having data of which other applications would benefit from having access to your data. Brett Shaffers's [OAuth2 Server ](http://bshaffer.github.io/oauth2-server-php-docs/) solution focuses on the server side of the interaction but provides both client and server components and both are now readily available to Restler customers who want to offer or connect-into the world of OAuth2. */ require_once "../../../vendor/restler.php"; use Luracast\Restler\Restler; $r = new Restler(); $r->addAuthenticationClass('Auth\\Server', ''); $r->setOverridingFormats('JsonFormat', 'HtmlFormat', 'UploadFormat'); $r->handle();
[![Forms](../resources/Form.gif)](users.html) We have made it easy to try different styles Also this example serves as an example for our Blade template integration See bootstrap3.blade.php and foundation5.blade.php Content: *[bootstrap3.blade.php]: _016_forms/views/base/bootstrap3.blade.php *[foundation5.blade.php]: _016_forms/views/base/foundation5.blade.php */ $loader = (include '../../../vendor/autoload.php'); $loader->setUseIncludePath(true); use Luracast\Restler\Data\Validator; use Luracast\Restler\Restler; use Luracast\Restler\Defaults; use Luracast\Restler\Format\HtmlFormat; use Luracast\Restler\UI\Forms; use Luracast\Restler\UI\FormStyles; HtmlFormat::$viewPath = __DIR__ . '/views'; HtmlFormat::$template = 'blade'; Validator::$holdException = true; $themes = array('amelia', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal', 'lumen', 'readable', 'simplex', 'slate', 'spacelab', 'superhero', 'united', 'yeti'); $theme = isset($_GET['theme']) ? $_GET['theme'] : $themes[array_rand($themes, 1)]; $style = $theme == 'foundation5' ? 'foundation5' : 'bootstrap3'; HtmlFormat::$data += compact('theme', 'themes', 'style'); Forms::$style = FormStyles::${$style}; $r = new Restler(); $r->setSupportedFormats('HtmlFormat'); $r->addAPIClass('Users'); $r->handle();
For example @url POST custom/path/{var1}/{var2} ### Wildcard Routes Wildcard routes allows our api methods to receive variable number of parameters they are manual routes that end with a star as the last path segment For example @url GET custom/path/* Take a look at the api class used here and compare it with the routes below to understand. Example 1: GET api/somanyways/1?p2=something returns "you have called Api::soManyWays()" Example 2: GET api/somanyways/1/2 returns "you have called Api::soManyWays()" Example 3: GET api/somanyways/1/2/3 returns "you have called Api::soManyWays()" Example 4: GET api/what/ever/you/want returns { "error": { "code": 400, "message": "Bad Request: anything is missing." } } Example 5: GET api/what/ever/you/want?anything=something returns "you have called Api::whatEver()" Example 6: GET api/all/1/2/3/4/5/6/7 returns "you have called Api::allIsMine(1, 2, 3, 4, 5, 6, 7)" Example 7: GET api/all returns "you have called Api::allIsMine()" */ require_once '../../../vendor/restler.php'; use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Api'); $r->handle();
Requires: PHP >= 5.3 Description: Shows the bare minimum code needed to get your RESTful api server up and running Example 1: GET math/add returns 2 Example 2: GET math/add?n1=6&n2=4 returns 10 Example 3: GET math/multiply/4/3 returns {"result":12} Example 4: GET math/multiply/4/NaN returns { "error": { "code": 400, "message": "Bad Request: invalid value specified for n2" } } Example 5: GET math/sum/1/2/3/4/5 returns 15 Content: > **Note:-** > > 1. Take note of the php doc comments, they make sure the data is sent in the > right type and validated automatically before calling the api method. > 2. Sum method accepts variable number of parameters with the help of > wildcard manual route. Read the [Routes](../_006_routing/readme.html) > example for better understanding */ require_once '../../../vendor/restler.php'; //smart auto loader helps loading a namespaced class with just the name part use Luracast\Restler\Restler; $r = new Restler(); $r->addAPIClass('Math'); $r->handle();
<?php error_reporting(0); header('Content-Type: application/json; charset=utf-8'); require 'vendor/autoload.php'; require 'Estafeta.php'; use Luracast\Restler\Restler; $rest = new Restler(); $rest->addAPIClass('Estafeta'); $rest->handle();
<?php /* * Testing all the attributes for @param annotation */ use Luracast\Restler\Restler; use Luracast\Restler\Defaults; require_once "../../../vendor/restler.php"; Defaults::$crossOriginResourceSharing = true; $r = new Restler(); $r->addAPIClass('MinMax'); $r->addAPIClass('MinMaxFix'); $r->addAPIClass('Type'); $r->addAPIClass('Resources'); $r->handle();
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();