- Apis\Api
- Apis\CachedApi
abstract class Apis \ CachedApi
Implements naive API caching using openclerk/cache
.
Method Summary
Name | Description |
---|---|
getAge() | How long are API calls cached? |
getCached($arguments) | |
getHash($arguments) | Return a 32-character hash from the given argmuents so that it can be cached. |
render($arguments) |
Try and get the JSON result for this API, and return either {success: true: result: $json} or {success: false, error: $message} if an exception occured. |
renderJSON($arguments) |
Inherited Method Summary
Name | Description |
---|---|
getEndpoint() | (from Api) |
getJSON($arguments) | Compile the JSON with the given arguments, as parsed from the #getEndpoint() string. (from Api) |
public function getAge()
How long are API calls cached?
- Returns:
number of seconds, default 60
public function getCached($arguments)
abstract function getHash($arguments)
Return a 32-character hash from the given argmuents so that it can be cached.
public function render($arguments)
Try and get the JSON result for this API, and return either
{success: true: result: $json}
or{success: false, error: $message}
if an exception occured.This means this Api can be used directly with
openclerk/routing
as a route callback:foreach (DiscoveredComponents\Apis::getAllInstances() as $uri => $handler) { \Openclerk\Router::addRoutes(array( $uri => $handler, )); }If openclerk/exceptions is installed, logs a new uncaught CaughtApiException if there was an exception that occured.
Caching can be achieved with a CachedApi.
- Overrides:
- render($arguments)