dev-master
9999999-devA library for defining and using APIs
The Requires
The Development Requires
0.1.0
0.1.0.0A library for defining and using APIs
The Requires
The Development Requires
Wallogit.com
2017 © Pedro Peláez
A library for defining and using APIs
A library for defining APIs in Openclerk, live on CryptFolio., (*1)
Include openclerk/apis as a requirement in your project composer.json,
and run composer update to install it into your project:, (*2)
{
"require": {
"openclerk/apis": "dev-master"
}
}
Define subclasses of \Apis\Api to define endpoints and content:, (*3)
/**
* API to get a single currency properties.
*/
class Currency extends \Apis\Api {
function getJSON($arguments) {
$cur = \DiscoveredComponents\Currencies::getInstance($arguments['currency']);
$result = array(
'code' => $cur->getCode(),
'title' => $cur->getName(),
);
return $result;
}
function getEndpoint() {
return "/api/v1/currency/:currency";
}
}
You can then call $api->render() for the specific API., (*4)
Your APIs can be discovered with component-discovery
by defining apis.json:, (*5)
{
"api/v1/currencies": "\\Core\\Api\\Currencies",
"api/v1/currency/:currency": "\\Core\\Api\\Currency"
}
You can then load these into openclerk/routing at runtime:, (*6)
// load up API routes
foreach (DiscoveredComponents\Apis::getAllInstances() as $uri => $handler) {
\Openclerk\Router::addRoutes(array(
$uri => $handler,
));
}
Using openclerk/cache you can also cache API calls:, (*7)
/**
* API to get a single currency properties.
*/
class Currency extends \Apis\CachedApi {
// ...
function getHash($arguments) {
return substr($arguments['currency'], 0, 32);
}
function getAge() {
return 60; /* cache age in seconds */
}
}
A library for defining and using APIs
A library for defining and using APIs