currency-exchangeapi-js
Version:
A Javascript currency exchange API key providing
41 lines (31 loc) • 859 B
JavaScript
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;