Get the latest exchange rate from the currencyapi.com
1
type Currencyapi = {
2
apiKey: string;
3
};
4
export async function main(
5
currencyApiResource: Currencyapi,
6
base_currency: string,
7
currencies: string,
8
) {
9
const paramString = new URLSearchParams({
10
base_currency: base_currency,
11
currencies: currencies,
12
}).toString();
13
14
const res = await fetch(
15
`https://api.currencyapi.com/v3/latest?${paramString}`,
16
{
17
headers: {
18
apikey: currencyApiResource.apiKey,
19
},
20
21
);
22
const data = await res.json();
23
const currency = data?.data;
24
return currency;
25
}
26