Minimal, idiomatic PHP client for OpenExchangeAPI
- All endpoints supported
- API key is optional
- Returns associative arrays for all responses
- Flexible for use in CakePHP, Laravel, Symfony, or any PHP project
Just copy OpenExchangeApiClient.php
into your project, or use Composer:
composer require openexchangeapi/openexchangeapi-php
use OpenExchangeApi\OpenExchangeApiClient;
$client = new OpenExchangeApiClient('YOUR_API_KEY'); // API key optional
// Get latest rates
$latest = $client->getLatest();
// Convert currency
$result = $client->convert('USD', 'EUR', 100);
// List currencies
$currencies = $client->listCurrencies();
// Get currency details
$eur = $client->getCurrency('EUR');
getLatest($base = null)
getLatestPrecise($base = null)
getHistorical($date, $base = null)
getHistoricalPrecise($date, $base = null)
convert($from, $to, $amount)
convertPrecise($from, $to, $amount)
listCurrencies($type = null)
getCurrency($code)
All methods throw OpenExchangeApiException
on error.
You can inject your own HTTP client (e.g., Guzzle, CakePHP, Laravel, Symfony):
$client = new OpenExchangeApiClient(null, null, function($url, $params) {
// ...your HTTP logic...
return $arrayResponse;
});
All errors throw OpenExchangeApiException
:
try {
$data = $client->getLatest();
} catch (OpenExchangeApiException $e) {
// Handle error
}
MIT