0.1.2 โข Published 6 months ago
@appaka/currapi v0.1.2
@appaka/currapi
Official Node.js client for currapi.com โ a simple API for historical currency exchange rates.
๐ฆ Install
npm install @appaka/currapior with Yarn:
yarn add @appaka/currapi๐ Usage
This client provides a modern and extensible way to interact with currapi.com, including automatic caching and validation.
๐ Set your API key
We recommend using environment variables to store your API key:
CURRAPI_API_KEY=your_api_key_hereCurrAPIClient class
import { CurrAPIClient } from '@appaka/currapi'
const client = new CurrAPIClient(process.env.CURRAPI_API_KEY!)
const rate = await client.getRate('USD', 'EUR', '2024-03-15')
const amount = await client.convert(100, 'USD', 'EUR', '2024-03-15')๐งฐ With optional cache support
import Redis from 'ioredis'
import { CurrAPIClient } from '@appaka/currapi'
const redis = new Redis(process.env.REDIS_URL!)
const client = new CurrAPIClient(process.env.CURRAPI_API_KEY!, {
verboseMode: true,
cacheGet: (base, target, date) => redis.get(`${date}:${base}${target}`),
cacheSet: (base, target, date, rate) =>
redis.set(`${date}:${base}${target}`, rate),
})๐ API Reference
getRate(base, target, date?)
Fetches the exchange rate for a given date. Defaults to today if not provided.
convert(amount, base, target, date?)
Converts an amount from one currency to another using the rate for a given date.
๐ฑ Supported Currencies
You can access the full list via:
import { CURRENCIES } from '@appaka/currapi'
console.log(CURRENCIES)
// ['EUR', 'USD', 'JPY', 'GBP', 'CHF', ...]๐งช TypeScript Support
All methods are fully typed. You can also use:
import type { Currency } from '@appaka/currapi'๐งโ๐ป Author
- Developed by javierperez.com | @javierperez_com
- Powered by currapi.com | @CurrAPI_com