UNPKG

currency-exchangeapi-js

Version:
41 lines (31 loc) 859 B
class Freecurrencyapi { baseUrl = 'https://api.freecurrencyapi.com/v1/'; constructor(apiKey = '') { this.headers = { apikey: apiKey }; } call (endpoint, params = {}) { const paramString = new URLSearchParams({ ...params }).toString(); return fetch(`${this.baseUrl}${endpoint}?${paramString}`, { headers: this.headers }) .then(response => response.json()) .then(data => { return data; }); } status () { return this.call('status'); } currencies (params) { return this.call('currencies', params); } latest (params) { return this.call('latest', params); } historical (params) { return this.call('historical', params); } } export default Freecurrencyapi;