1
Latest exchange rate from CurrencyApi.com
One script reply has been approved by the moderators Verified

Get the latest exchange rate from the currencyapi.com

Created by sindre svendby964 625 days ago Viewed 9782 times
0
Submitted by sindre svendby964 Deno
Verified 625 days ago
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