1. Go to this page and download the library: Download richardgomer/quapi library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
richardgomer / quapi example snippets
ckAPI as API;
/**
* Some action that the API performs
*/
class Action1 implements API\APIHandler,
{
public function handleCall($args)
{
// Do something
// Return a foo
return new Foo();
}
}
/**
* Convert a foo object into a JSON-serializable array
*/
class FooConverter implements API\APIResultHandler
{
public function prepareResult($res)
{
// Bars will be converted into arrays by the BarConverter later on :)
return array('name' => $res->name, 'bars' => $res->getBars());
}
}
/**
* Convert a bar object into a JSON-serializable array
*/
class BarConverter implements API\APIResultHandler
{
public function prepareResult($res)
{
return array('barID' => $res->BarID, 'colour' => $bar->getColour());
}
}
/**
* Create an API that looks for arguments in $_GET/$_POST and uses the "action" argument to specify which
* action handler to invoke
*/
$api = new API\API(\array_merge($_GET, $_POST), 'action');
/**
* Add an action to be called if the action parameter is "action1" or if "param1" is set
*/
$a1 = new Action1();
$api->addOperation(false, array('param1'), $fi);
$api->addOperation('action1', array('param1'), $fi);
/**
* Register converters to turn Foo objects and Bar objects in json-serializable arrays
*/
$api->registerResultHandler('Foo', new FooConverter());
$api->registerResultHandler('Bar', new BarConverter());
// Handle the request
$api->handle();
$api->addAuth(new AuthHandler()); // $authHandler must implement APIAuth
<script>
s API;
echo getAPIClient();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.