Making currency rate requests in Java with CompletableFuture
Thread-safety


  I'm worried about thread-safety !! :x


I don't see any shared data anywhere,
and as such there are no visible thread-safety issues.

If you called CurrencyLayer.lookUpRates from multiple threads,
then CurrencyLayer.client would be shared and so it would need to be thread-safe.

The current program as it is,
fetches and processes exchange rates practically sequentially,
so there's no visible need for multi-threading,
and doesn't really benefit at all from CompletableFuture.
There is no visible reason for CurrencyLayer.lookUpRates to return CompletableFuture&lt;List&lt;ForexRate&gt;&gt;,
it could as well return a simple List&lt;ForexRate&gt;.

Unused method parameter


private CompletableFuture&lt;Response&gt; makeRequest(List&lt;CurrencyPair&gt; pairs) {
    final String url = "http://www.apilayer.net/api/live?access_key=[my key ^^]&amp;format=1";
    return CompletableFuture.supplyAsync(() -&gt; client.target(url).request().get());
}



The pairs parameter is not used in this method.

Exception handling in main

In this code,
it would be better to remove the try-catch.
The outcome will look the same in case of failure,
but the exit code will be correctly non-zero,
which is currently not the case.


static public void main(String[] args) {
    CurrencyLayer c = new CurrencyLayer();
    try {
        // ...
    } catch (Exception e) {
        e.printStackTrace();
    }
}