OpenRates Currency API (Sponsored)

Publikováno: 30.5.2018

Creating your own APIs can be a total nightmare: worrying about uptime, load balancing, data accuracy, caching, and all of the other risks would keep me up at night.  And if your API relates to money in any way?  If you get that wrong you could be costing yourself, your employer, or your client a […]

The post OpenRates Currency API (Sponsored) appeared first on David Walsh Blog.

Celý článek

Creating your own APIs can be a total nightmare: worrying about uptime, load balancing, data accuracy, caching, and all of the other risks would keep me up at night.  And if your API relates to money in any way?  If you get that wrong you could be costing yourself, your employer, or your client a ton of money.  I’ve been playing around with OpenRates lately and it’s been really simple to use.  Let’s have a look!

Quick Hits

  • Based on fixer.io
  • Open source, available here!
  • Data is sourced from the European Central Bank
  • Get current and historical currency rates
  • Free (no API key required either)
  • 100% uptime
  • Specify base and desired currencies
  • Supports JSONP

Using OpenRates

The EUR is the base currency, so if that matches your base, you can simply GET the following:

curl http://api.openrates.io/latest

/*
{
    "base":"EUR",
    "date":"2018-05-25",
    "rates": {
        "GBP":0.8754,
        "USD": 1.1675
    }
    ....
}
*/

It’s probably safer to specify your desired base currency, which you can do with a simple parameter:

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

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

You can also customize the currencies you’d like returned:

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

If you want historical data, you can specify a date:

curl http://api.openrates.io/2018-01-10?symbols=USD,GBP,EUR,AUD 

Want JSONP?  No problem:

$.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
    }
});

APIs should be simple, secure, and reliable, and OpenRates certainly fits that bill.  Not needing an API key is nice, and the data structure returned is ultra simple.  Give OpenRates a look if you need accurate, reliable currency information!

The post OpenRates Currency API (Sponsored) appeared first on David Walsh Blog.

Nahoru
Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tímto souhlasíte. Další informace