PHP code example of api-clients / transport

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

    

api-clients / transport example snippets


$locator = new MiddlewareLocator(); // A concrete class implementing the middleware locator interface 
$loop = EventLoopFactory::create(); // The event loop
$options = []; // Client options, as described below
$client = Factory::create($locator, $loop, $options);

$request = new PsrRequest(); // 
$requestOptions = []; // Options such as middleware settings
$client->request($request, $requestOptions)->done(function (ResponseInterface $response) {
    // Handle the response
});

$options = [
    Options::DEFAULT_REQUEST_OPTIONS => [
        \ApiClients\Middleware\Delay\DelayMiddleware::class => [
            \ApiClients\Middleware\Delay\Options::DELAY => 3,
        ],
    ],
    Options::MIDDLEWARE => [
        \ApiClients\Middleware\Delay\DelayMiddleware::class,
    ],
];

$client = new Client($loop, $container, $browser, $options);

$requestOptions = [
    \ApiClients\Middleware\Delay\DelayMiddleware::class => [
        \ApiClients\Middleware\Delay\Options::DELAY => 5,
    ],
];
$client->request($request, $requestOptions);