0.1.2 โ€ข Published 6 months ago

@appaka/currapi v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

@appaka/currapi

Official Node.js client for currapi.com โ€” a simple API for historical currency exchange rates.

๐Ÿ“ฆ Install

npm install @appaka/currapi

or 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_here

Get your API key.


CurrAPIClient 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

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago