fixer-api
fixer.io API client in TypeScript
Last updated a month ago by svlapin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fixer-api 
SYNC missed versions from official npm registry.

fixer.io API client for Node.js and browser written in TypeScript

Build Status codecov npm version

TypeScript

Known Vulnerabilities

Features

  • works in both Node.js and browser
  • promise or async / await based
  • extensively tested with unit and integration tests.

API key

To use fixer API, you must obtain an Access Key first https://fixer.io/.

Install

npm install fixer-api

Usage

Import default fixer instance

const fixer = require('fixer-api');

Set accessKey obtained from fixer.io

fixer.set({ accessKey: '<YOUR API KEY>' })

.set supports chaining, so you can run a query right after, e.g.:

await fixer
  .set({ accessKey: '<YOUR API KEY>' })
  .latest();

Fetch the latest data with .latest

const data = await fixer.latest();
console.log(data);

/**
 *  or, if you want to specify access key per request (note it's in snake_case here)
 */
const data = await fixer.latest({ access_key: '<YOUR API KEY>' });
console.log(data);

/*
{
  base: 'EUR',
  date: '2017-01-30',
  rates: {
    AUD: 1.4109,
    BGN: 1.9558,
    BRL: 3.3318,
    CAD: 1.3983,
    CHF: 1.0669,
    CNY: 7.3103,
    CZK: 27.022,
    DKK: 7.4375,
    GBP: 0.84935,
    HKD: 8.2476,
    HRK: 7.4773,
    HUF: 310.8,
    IDR: 14173,
    ILS: 4.0228,
    INR: 72.232,
    JPY: 121.76,
    KRW: 1252.3,
    MXN: 22.085,
    MYR: 4.7094,
    NOK: 8.8758,
    NZD: 1.4668,
    PHP: 52.899,
    PLN: 4.331,
    RON: 4.5008,
    RUB: 63.779,
    SEK: 9.439,
    SGD: 1.5177,
    THB: 37.492,
    TRY: 4.0561,
    USD: 1.063,
    ZAR: 14.451
  }
}
/*

Fetch latest data based on specific base currency

const data = await fixer.latest({ base: 'USD', symbols: ['CHF'] });
console.log(data);

/*
{ base: 'USD', date: '2017-01-30', rates: { CHF: 1.0037 } }
*/

Fetching historical data with .forDate

const data = await fixer.forDate('2015-04-01', { base: 'USD', symbols: ['CHF'] });

/**
 *  or, if you want to specify access key per request (note it's in snake_case here)
 */
const data = await fixer.forDate('2015-04-01', {
  access_key: '<YOUR API KEY>', ]
  base: 'USD',
  symbols: ['CHF']
});
console.log(data);

or by providing Date instance:

const data = await fixer.forDate(new Date(), { base: 'USD', symbols: ['CHF'] });

Doing currency conversion with .convert

Keep in mind that .convert requires a paid fixer plan.

fixer.convert(<from>, <to>, <amount>, <date? = current date>)
const data = await fixer.convert('GBP', 'JPY', 25, "2018-02-22");
console.log(data);

/*
  success: true,
  query: {
    from: "GBP",
    to: "JPY",
    amount: 25
  },
  info: {
    timestamp: 1519328414,
    rate: 148.972231
  },
  date: "2018-02-22"
  result: 3724.305775
*/

Running tests

Unit tests

Unit tests run in isolation and don't send real requests to fixer.io.

npm test

Integration tests

Integration tests send real requests to fixer.io and so require valid access key.

FIXER_API_KEY="<YOUR_FIXER_KEY_HERE>" npm run test:integration

Using in browser

dist folder of packaged npm module includes browser bundles: fixer.iife.js and fixer.iife.min.js (minified version). Each bundle exposes an instance of fixer as fixerApi global variable.

Typical usage is as follows (supposing web server is serving node-modules):

<body>
  <script src="node-modules/fixer-api/dist/fixer.iife.min.js"></script>
  <script>
    fixerApi.set({ accessKey: '<YOUR_FIXER_KEY_HERE>' })
      .latest()
      .then((result) => {
        console.log(result)
      });
  </script>
</body>

or by using unpkg CDN:

<body>
  <script src="https://unpkg.com/fixer-api/dist/fixer.iife.min.js"></script>
  <script>
    fixerApi.set({ accessKey: '<YOUR_FIXER_KEY_HERE>' })
      .latest()
      .then((result) => {
        console.log(result)
      });
  </script>
</body>

Current Tags

  • 2.0.1                                ...           latest (a month ago)

22 Versions

  • 2.0.1                                ...           a month ago
  • 2.0.0                                ...           4 months ago
  • 1.5.0                                ...           5 months ago
  • 1.4.4                                ...           5 months ago
  • 1.4.3                                ...           5 months ago
  • 1.4.2                                ...           5 months ago
  • 1.4.1                                ...           8 months ago
  • 1.4.0                                ...           8 months ago
  • 1.3.3                                ...           8 months ago
  • 1.3.2                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.7                                ...           a year ago
  • 1.2.6                                ...           2 years ago
  • 1.2.5                                ...           2 years ago
  • 1.2.4                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.2.1                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 45
Last Day 0
Last Week 0
Last Month 36
Dependencies (1)
Dev Dependencies (13)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |