PHP code example of thomas-institut / apm-publication-api

1. Go to this page and download the library: Download thomas-institut/apm-publication-api 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/ */

    

thomas-institut / apm-publication-api example snippets


use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
use ThomasInstitut\ApmPublicationApi\Client\PublicationApiClient;

// 1. Create the PSR-18 HTTP Client (Guzzle 7+ implements this)
$httpClient = new Client();

// 2. Create the PSR-17 Request Factory (Guzzle PSR-7 provides this)
$requestFactory = new HttpFactory();

// 3. Define the base URL of the APM API (without /publication)
$baseUrl = 'https://apm.example.com/api';

// 4. Initialize the PublicationApiClient
$apiClient = new PublicationApiClient(
    $httpClient,
    $requestFactory,
    $baseUrl
);

// Optional: you can also provide a logger and enable debug mode
// $apiClient = new PublicationApiClient($httpClient, $requestFactory, $baseUrl, $logger, true);

// Example usage:
try {
    $listResponse = $apiClient->list();
    foreach ($listResponse->publications as $listing) {
        echo $listing->title . PHP_EOL;
    }
} catch (\ThomasInstitut\ApmPublicationApi\Client\PublicationApiClientException $e) {
    // Handle transport or server errors
}