You are here

How to Use the OpenRates Currency API

You can convert currency and access live exchange rates data with the OpenRates Currency API. Open Rates API is open source, no API Key is required, the data is sourced from the European Central Bank, and is based on Fixer.io, a currency conversion JSON API. David Walsh explains in his tutorial how you will GET euros as a requested currency, use a parameter, and customize currencies. You have the option to access historical data and use JSONP.

Since EUR is the base currency, ensure it matches your base by using the GET verb:

curl http://api.openrates.io/latest
/*  
{
   "base":"EUR",
   "date":"2018-05-25",
   "rates": {
       "GBP":0.8754,
       "USD": 1.1675
   }
   ....
}
*/

To determine a base currency, you can add a parameter like the example below: 

curl http://api.openrates.io/latest?base=USD

/*
{
    "base":"GBP",
    "date":"2018-05-25",
    "rates": {
        "AUD":1.7619,
        ....
        "USD":1.3337
    }
}
*/

And customize currencies to display in a response:

curl http://api.openrates.io/latest?symbols=USD,GBP,EUR,AUD

The author also mentions a JSONP method, requesting jQuery and working with the response:

$.ajax({
   url: "http://api.openrates.io/latest",
   // The name of the callback parameter
   jsonp: "my_callback_fn",
   // Tell jQuery we're expecting JSONP
   dataType: "jsonp",
   // Work with the response
   success: function( response ) {
       console.log( response ); // server response
   }
});

OpenRates displays data for 32 world currencies in JSON format, updated daily at around 4:00pm CET.
 

Original Article

OpenRates Currency API

Mayela Gonzalez Mayela Gonzalez is a Writer, Researcher, & Web Content Editor at ProgrammableWeb.com
 

Comments