Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Exchange Rate API - PHP Package

Exchange Rate is a simple tool for getting the current exchange rate between two currencies. It returns the current exchange rate.

Installation

Install via Composer:

composer require apiverve/exchangerate

Getting Started

Get your API key at APIVerve

Basic Usage

<?php

require_once 'vendor/autoload.php';

use APIVerve\Exchangerate\Client;

// Initialize the client
$client = new Client('YOUR_API_KEY');

// Make a request
$response = $client->execute([
    'currency1' => 'USD',
    'currency2' => 'EUR'
]);

// Print the response
print_r($response);

Error Handling

use APIVerve\Exchangerate\Client;
use APIVerve\Exchangerate\Exceptions\APIException;
use APIVerve\Exchangerate\Exceptions\ValidationException;

try {
    $response = $client->execute(['currency1' => 'USD', 'currency2' => 'EUR']);
    print_r($response['data']);
} catch (ValidationException $e) {
    echo "Validation error: " . implode(', ', $e->getErrors());
} catch (APIException $e) {
    echo "API error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
}

Debug Mode

// Enable debug logging
$client = new Client(
    apiKey: 'YOUR_API_KEY',
    debug: true
);

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "currency1": "USD",
    "currency2": "EUR",
    "exchangeRate": "0.851223",
    "inverseRate": "1.174773"
  }
}

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client

Documentation

For more information, visit the API Documentation.

Support

License

This package is available under the MIT License.