1

Latest exchange rate from CurrencyApi.com

by
Published Apr 13, 2023

Get the latest exchange rate from the currencyapi.com

Script currencyapi Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
type Currencyapi = {
4
  apiKey: string;
5
};
6
export async function main(
7
  currencyApiResource: Currencyapi,
8
  base_currency: string,
9
  currencies: string,
10
) {
11
  const paramString = new URLSearchParams({
12
    base_currency: base_currency,
13
    currencies: currencies,
14
  }).toString();
15

16
  const res = await fetch(
17
    `https://api.currencyapi.com/v3/latest?${paramString}`,
18
    {
19
      headers: {
20
        apikey: currencyApiResource.apiKey,
21
      },
22
    },
23
  );
24
  const data = await res.json();
25
  const currency = data?.data;
26
  return currency;
27
}
28

Other submissions
  • Submitted by sindre svendby964 Deno
    Created 398 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