SDKs overview
Currency-api offers a suite of official SDKs designed to simplify integration with its currency exchange rate API. These SDKs abstract away the complexities of HTTP requests and response parsing, allowing developers to focus on application logic. By providing language-specific interfaces, they enable efficient access to real-time, historical, and timeseries currency data. The availability of SDKs across multiple popular programming languages caters to a broad developer base, ensuring compatibility with diverse project requirements and existing tech stacks. The Currency-api documentation provides detailed guides and examples for each supported language, facilitating a smooth onboarding process for developers looking to incorporate currency functionality into their applications.
Beyond the official offerings, the open nature of web APIs often leads to the development of community-contributed libraries. While official SDKs are maintained directly by Currency-api, community libraries can offer alternative implementations or extensions, sometimes catering to niche use cases or specific frameworks not directly covered by official support. Developers often consult the official Currency-api documentation for the most up-to-date information on API endpoints and data structures, which is crucial for both official and community library development and maintenance, as detailed in the Currency-api API documentation.
Official SDKs by language
Currency-api provides official SDKs for several programming languages, ensuring direct support and maintenance. These SDKs are developed and maintained by Currency-api, offering reliable and up-to-date access to the API's features. Each SDK is designed to align with the conventions and best practices of its respective language, providing a native development experience. The table below outlines the officially supported languages and their corresponding packages, along with typical installation commands and their general maturity status.
| Language | Package/Module | Installation Command (Example) | Maturity |
|---|---|---|---|
| PHP | currencyapi/currencyapi-php |
composer require currencyapi/currencyapi-php |
Stable |
| Python | currencyapi-python |
pip install currencyapi-python |
Stable |
| JavaScript | @currencyapi/js |
npm install @currencyapi/js |
Stable |
| Go | github.com/currencyapi/go-currencyapi |
go get github.com/currencyapi/go-currencyapi |
Stable |
| Ruby | currencyapi-ruby |
gem install currencyapi-ruby |
Stable |
| Java | currencyapi-java |
Add to pom.xml or build.gradle |
Stable |
| C# | CurrencyApi.Net |
dotnet add package CurrencyApi.Net |
Stable |
Installation
Installing Currency-api SDKs typically involves using the package manager specific to your programming language. These commands fetch the necessary libraries and dependencies, making them available for use in your project. It's recommended to refer to the Currency-api official documentation for the most current and detailed installation instructions, as package versions and specific commands can evolve over time. Below are general installation guidelines for some of the supported languages:
PHP
For PHP projects, Composer is the standard package manager. You can install the Currency-api PHP SDK by running:
composer require currencyapi/currencyapi-php
Python
Python developers use pip to install packages from the Python Package Index (PyPI). To install the Python SDK:
pip install currencyapi-python
JavaScript (Node.js/Browser)
For JavaScript environments, npm or yarn are commonly used. Install the JavaScript SDK:
npm install @currencyapi/js
Or with Yarn:
yarn add @currencyapi/js
Go
Go modules are used for dependency management in Go projects. To add the Go SDK:
go get github.com/currencyapi/go-currencyapi
Ruby
RubyGems is the package manager for Ruby. Install the Ruby SDK using:
gem install currencyapi-ruby
Java
For Java, dependencies are typically managed with Maven or Gradle. Add the following to your pom.xml (Maven):
<dependency>
<groupId>com.currencyapi</groupId>
<artifactId>currencyapi-java</artifactId>
<version>1.0.0</version> <!-- Replace with the latest version -->
</dependency>
Or to your build.gradle (Gradle):
implementation 'com.currencyapi:currencyapi-java:1.0.0' // Replace with the latest version
C#
For C# and .NET projects, NuGet is the package manager. Install the C# SDK using the .NET CLI:
dotnet add package CurrencyApi.Net
Or via the NuGet Package Manager Console in Visual Studio:
Install-Package CurrencyApi.Net
Quickstart example
This quickstart example demonstrates how to fetch the latest exchange rates using the Currency-api JavaScript SDK. This snippet initializes the client with an API key and then makes a request to retrieve the latest rates, logging the result. For additional examples in other languages, consult the Currency-api developer documentation.
JavaScript (Node.js)
const CurrencyAPI = require('@currencyapi/js');
const currencyapi = new CurrencyAPI('YOUR_API_KEY');
currencyapi.latest({
base_currency: 'USD',
currencies: 'EUR,GBP,JPY'
}).then(response => {
console.log(response.data);
}).catch(error => {
console.error('Error fetching currency rates:', error);
});
Replace 'YOUR_API_KEY' with your actual API key obtained from your Currency-api account. This example fetches the latest exchange rates for EUR, GBP, and JPY, based on USD.
Python
The Python SDK provides a similar straightforward interface:
from currencyapi import CurrencyAPI
currency_api = CurrencyAPI('YOUR_API_KEY')
try:
response = currency_api.latest(base_currency='USD', currencies='EUR,GBP,JPY')
print(response.data)
except Exception as e:
print(f"Error fetching currency rates: {e}")
PHP
For PHP, the SDK uses a similar object-oriented approach:
<?php
require_once 'vendor/autoload.php';
use CurrencyAPI\CurrencyAPI;
$currencyapi = new CurrencyAPI('YOUR_API_KEY');
try {
$response = $currencyapi->latest([
'base_currency' => 'USD',
'currencies' => 'EUR,GBP,JPY'
]);
print_r($response['data']);
} catch (Exception $e) {
echo 'Error fetching currency rates: ' . $e->getMessage();
}
?>
Community libraries
While Currency-api maintains official SDKs for major programming languages, the developer community may also contribute unofficial libraries or wrappers. These community-driven projects can offer additional functionalities, integrations with specific frameworks, or alternative API access patterns. Developers often share these resources on platforms like GitHub or package repositories specific to their language (e.g., PyPI for Python, npm for JavaScript).
It is important to note that community libraries are not officially supported or maintained by Currency-api. Their reliability, security, and adherence to the latest API specifications can vary. Before incorporating a community library into a production environment, developers should review its source code, check its maintenance status, and verify its compatibility with the official Currency-api API reference. For example, a common practice in API integration is to validate the library's handling of authentication, error responses, and rate limits, as outlined in general API security best practices by providers like Google Developers. While Currency-api does not endorse specific community libraries, developers are encouraged to explore the broader ecosystem for tools that meet their unique project requirements.