apilayer-fixer
v1.0.3
Published
Fixer API SDK
Downloads
70
Readme
Fixer SDK
A lightweight JavaScript SDK for interacting with the Fixer API. This SDK allows you to retrieve exchange rate data, convert currencies, and more, using the Fixer API.
Installation
Install the package using npm or yarn:
npm install apilayer-fixer
# or
yarn add apilayer-fixer
Usage
Import the SDK
import Fixer from "apilayer-fixer";
Initialize the SDK
const fixer = new Fixer("your_api_key");
Replace "your_api_key"
with your actual API key from Fixer API.
Available Methods
1. symbols()
Retrieve available currency symbols.
fixer.symbols().then((data) => console.log(data));
2. latest(params)
Get the latest exchange rates.
- Parameters: An object with optional parameters such as
symbols
(comma-separated list of currencies) andbase
(base currency).
fixer.latest({ symbols: "USD,EUR", base: "GBP" }).then((data) => console.log(data));
3. convert(params)
Convert an amount from one currency to another.
- Parameters: An object with the following properties:
from
: Source currency.to
: Target currency.amount
: Amount to convert.
fixer.convert({ from: "USD", to: "EUR", amount: 100 }).then((data) => console.log(data));
4. timeseries(params)
Get historical exchange rates for a specific date range.
- Parameters: An object with the following properties:
start_date
: Start date inYYYY-MM-DD
format.end_date
: End date inYYYY-MM-DD
format.base
(optional): Base currency.symbols
(optional): Comma-separated list of currencies.
fixer.timeseries({ start_date: "2023-01-01", end_date: "2023-01-31", base: "USD" }).then((data) => console.log(data));
5. fluctuation(params)
Get information about fluctuations in exchange rates.
- Parameters: An object with the following properties:
start_date
: Start date inYYYY-MM-DD
format.end_date
: End date inYYYY-MM-DD
format.base
(optional): Base currency.symbols
(optional): Comma-separated list of currencies.
fixer.fluctuation({ start_date: "2023-01-01", end_date: "2023-01-31" }).then((data) => console.log(data));
Error Handling
The SDK will throw errors if the API key is invalid or if there are issues with the API request. Ensure you handle errors in your code:
fixer
.latest()
.then((data) => console.log(data))
.catch((error) => console.error("Error fetching data:", error));
API Documentation
For more information about available endpoints and parameters, refer to the Fixer API Documentation.
License
This package is licensed under the MIT License.