Integrating with the Global Exchange Rates API is straightforward via our JSON and XML endpoints. To simplify things for Java developers, we’ve released an official Java client library available on Maven Central.
This library works well with standard Java projects and is fully compatible with Android development, making it easy to add reliable exchange rate data to mobile apps or backend services.
You can find the package here: globalexchangerates-client on Maven Central.
Getting Started
Add the dependency to your project:
Maven
<dependency>
<groupId>org.globalexchangerates</groupId>
<artifactId>globalexchangerates-client</artifactId>
<version>1.0.0</version>
</dependency>
Gradle
implementation 'org.globalexchangerates:globalexchangerates-client:1.0.0'
Usage
Create an instance of the client with your API key:
GlobalExchangeRatesClient client = new GlobalExchangeRatesClient("YOUR_API_KEY");
You can then call API methods asynchronously. For example, fetching the latest exchange rates:
CompletableFuture<ExchangeRateResponse> ratesFuture = client.getLatestAsync(null, null, null);
ratesFuture.thenAccept(rates -> {
System.out.println("Base currency: " + rates.getBase());
System.out.println("Provider: " + rates.getProvider());
System.out.println("Date: " + rates.getDate());
rates.getExchangeRates().forEach((currency, rate) ->
System.out.println(currency + ": " + rate));
});
Converting Amounts and Historical Rates
Convert an amount directly using the official rates:
client.convertAsync(100, "EUR", List.of("USD", "GBP"), null, null)
.thenAccept(result -> System.out.println(result.getConversions()));
Retrieve the official rates for a specific date:
LocalDate date = LocalDate.of(2025, 1, 1);
client.getHistoricalAsync(date, null, null, List.of("USD"), "EUR")
.thenAccept(rates -> System.out.println(rates.getExchangeRates()));
Providers and Error Handling
Request rates from a single provider such as the ECB, or list the available institutions:
client.getLatestAsync("ECB", List.of("USD", "GBP"), null)
.thenAccept(rates -> System.out.println(rates.getExchangeRates()));
client.getProvidersAsync(null, null)
.thenAccept(providers -> providers.forEach(System.out::println));
API errors surface as an ApiException in the future’s exception handler:
client.getLatestAsync(null, List.of("USD"), "EUR")
.exceptionally(ex -> {
System.err.println("API error: " + ex.getMessage());
return null;
});
Keeping the Rates Up to Date
Official rates are published once per business day, so refreshing on a schedule is usually enough to keep your data current.
The same official rates are available in other languages and tools — see our Python, C# / .NET, JavaScript, and Go client libraries, or the guides for Power BI and Google Sheets. The full method reference is in the API documentation. If you don’t have an API key yet, you can get one on the get-started page, with official rates from central banks and tax authorities worldwide.
If you’re building Java or Android apps that need currency exchange data, this client library should help you integrate our API quickly and reliably.