PHP code example of bokbasen / php-api-client

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

    

bokbasen / php-api-client example snippets


use Bokbasen\Auth\Login;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

try {
    /* This example is using a file cache for the TGT, you can replace this with any PSR-6 
        compatible cache. Always using caching in production to avoid performance penalty of 
        creating and deleting tokens.
    */
    $cache = new FilesystemAdapter();
    $login = new Login('username', 'password', Login::URL_PROD, $cache);
} catch(\Throwable $e) {
    // error handling
}

use Bokbasen\ApiClient\Client;
use Bokbasen\ApiClient\HttpRequestOptions;
use Bokbasen\ApiClient\Exceptions\BokbasenApiClientException;

try {
    /* Pass the base URL of the API you are interacting with. You can also pass a logger 
        and a custom http client. Any request made through the API returns an instance 
        of \Psr\Http\Message\ResponseInterface.  All of these API calls will n('/path', $body, $headers);
    
    // Execute POST request 
    $response = $client->post('/path', $body, $headers);
    
    // Execute PUT request
    $response = $client->put('/path', $body, $headers);
    
    // Execute PATCH request
    $response = $client->patch('/path', $body, $headers);
} catch(BokbasenApiClientException $e){
    //error handling
}

$ composer