@everapi/freecurrencyapi-js
Version:
A JavaScript wrapper for the freecurrencyapi.com's API
43 lines (32 loc) • 874 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;