;

Javascript Example Code

To access our Exchange Rates API in Javascript you will need to consider implications of storing your API key. Javascript in a browser is not secure, and your API key can be viewed by any user. This is fine for intranet type applications but you must ensure when using this on a public site you secure you API key using another method.

Also note that if you are using javascript you will likely need to operate your API requests under JSONP formatting. See the below example.

Get Exchange Rates using JQuery Examples

We recommend Jquery for getting exchange rates using javascript.

Get Latest Exchange Rates

 $.ajax({
        url: "http://api.exchangeratelab.com/api/current?apikey=YOURAPIKEY",
        // the name of the callback parameter
        jsonp: "callback",
        // tell jQuery we're expecting JSONP
        dataType: "jsonp",
        // work with the response
        success: function (response) {
           console.log(JSON.stringify(response)); // server response
        }
    });

Currency Conversion Example (This is only available in the Premium API)

    $.ajax({
        url: "http://api.exchangeratelab.com/api/convert?apikey=YOURAPIKEY&from=GBP&to=USD&amount=9.99",
        // the name of the callback parameter
        jsonp: "callback",
        // tell jQuery we're expecting JSONP
        dataType: "jsonp",
        // work with the response
        success: function (response) {
           console.log(JSON.stringify(response)); // server response
        }
    });
ExchangeRateLab © 2013 - 2015