PHP code example of axo3 / api-client

1. Go to this page and download the library: Download axo3/api-client 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/ */

    

axo3 / api-client example snippets




use Axo3\ApiClient\Client\ApiClient;
use Axo3\ApiClient\Service\UnitsSnapshotService;
use Axo3\ApiClient\SnapshotConfig;
use Axo3\ApiClient\Store\SnapshotStore;

$config = new SnapshotConfig(
    dataDir: '/path/to/storage/axo3-units',   // outside the web root
    logFile: '/path/to/storage/axo3-units/sync.log',
);

$service = new UnitsSnapshotService(
    new SnapshotStore($config),
    $config,
    new ApiClient('https://api.axo3.ch', 'YOUR-API-KEY'),
);

// Render path: reads the local snapshot, NEVER calls the API.
foreach ($service->units() as $unit) {
    echo $unit['title'], ' — ', $unit['status'], "\n";
}

// Background path (after rendering, or from a cron/scheduled job):
// asks the API only when the interval it dictated has elapsed.
$service->revalidateIfDue();

$service = new UnitsSnapshotService($store, $config, $client,
    function ($result) {
        if (!$result->isSuccess()) {
            // notify yourself; $result->code and $result->message say why
        }
    }
);