How it works...

Similar to the previous example we saw, which uses an external program to achieve a specific task, this time we used an external service provider that provided us with an open Application Programming Interface (API) that is free for all and easy to use.

This way, we don't have to think about the method used to retrieve the latest currency rate. Instead, the service provider has already done the job for us; we just have to send a polite request to ask for it. Then, we wait for the response from their server and process the data according to our intended purposes.

There are quite a few different service providers you can choose from, besides Fixer.io (http://fixer.io). Some are free, but come without any advanced features; some provide you with premium price. Some of these alternatives are open exchange rates (https://openexchangerates.org), currencylayer API (https://currencylayer.com), Currency API (https://currency-api.appspot.com), XE Currency Data API (http://www.xe.com/xecurrencydata), and jsonrates (http://jsonrates.com).

In the previous code, you should have noticed an access key being passed to the Fixer.io API, which is a free access key I registered for this tutorial. If you are using it for your own project, you should create an account at Fixer.io.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset