PHP code example of kreyu / nbp-web-api

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

    

kreyu / nbp-web-api example snippets


use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Api\ExchangeRates;

$client = new Client();

// Example call
$client->exchangeRates(ExchangeRates::TABLE_TYPE_A)->forCurrency('EUR')->latest(5);

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\ClientInterface;

$client = new Client();
$client->setContentType(ClientInterface::CONTENT_TYPE_XML);

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/**
 * @var $client         Psr\Http\Client\ClientInterface
 * @var $requestFactory Psr\Http\Message\RequestFactoryInterface
 * @var $streamFactory  Psr\Http\Message\StreamFactoryInterface
 * @var $uriFactory     Psr\Http\Message\UriFactoryInterface
 */

$builder = new HttpClientBuilder(
    $client,
    $requestFactory,
    $streamFactory,
    $uriFactory
);

$client = new Client($builder);

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/** @var $pool Psr\Cache\CacheItemPoolInterface */

$builder = new HttpClientBuilder();
$builder->setCache($pool);

$client = new Client($builder);

use Kreyu\NBPWebApi\Client;
use Kreyu\NBPWebApi\Http\ClientBuilder as HttpClientBuilder;

/** @var $plugin Http\Client\Common\Plugin */

$builder = new HttpClientBuilder();
$builder->addPlugin($plugin);

$client = new Client($builder);