fawazahmed0/exchange-api Documentation

repository·main·Indexed 25 days ago

https://github.com/fawazahmed0/exchange-api

A free, high-performance API providing daily updated exchange rates for over 200 currencies, including metals and cryptocurrencies. The API supports historical data via YYYY-MM-DD dates, provides both prettified and minified JSON responses, and offers a Cloudflare-hosted fallback mechanism for high availability.

Tokens
684
Snippets
3
Records
4
Agent score
33%

What's inside fawazahmed0/exchange-api

  1. Access the Free Currency Exchange Rates API

    main

    The Exchange API provides free, fast access to exchange rates for over 200 currencies, including cryptocurrencies and metals. Data is updated daily and has no rate limits.

    To use the API, construct a URL using the following structure: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{date}/{apiVersion}/{endpoint}

    URL Components:

    • {date}: Use latest for the most recent data or a specific date in YYYY-MM-DD format (e.g., 2024-03-06).
    • {apiVersion}: Currently v1.
    • {endpoint}: The specific resource you want to access (e.g., currencies or currencies/{currencyCode}).

    Response Formats:

    The API supports HTTP GET and returns JSON in two formats:

    • /{endpoint}.json: Standard prettified JSON.
    • /{endpoint}.min.json: Minified JSON for reduced payload size.
    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json
  2. Implement a fallback mechanism for API requests

    main

    To ensure high availability, you should implement a fallback mechanism in your code. If the primary cdn.jsdelivr.net URL fails, your application should attempt to fetch from the Cloudflare-hosted fallback URL.

    Primary URL Structure: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@{date}/{apiVersion}/{endpoint}

    Fallback URL Structure: https://{date}.currency-api.pages.dev/{apiVersion}/{endpoint}

    Fallback Examples:

    • Latest EUR rates: https://latest.currency-api.pages.dev/v1/currencies/eur.json
    • Historical EUR rates (2024-03-06): https://2024-03-06.currency-api.pages.dev/v1/currencies/eur.json
  3. Get exchange rates for a specific base currency

    main

    To retrieve exchange rates relative to a specific base currency, use the /currencies/{currencyCode} endpoint. You can specify a date to retrieve historical rates.

    Examples:

    • Latest rates with EUR as base:

    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.json

    • Latest rates with BTC as base (minified):

    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/btc.min.json

    • Historical rates (2024-03-06) with EUR as base:

    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@2024-03-06/v1/currencies/eur.json

    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.json
  4. List all available currencies

    main

    To get a list of all supported currencies and their metadata in a prettified JSON format, use the /currencies endpoint.

    Standard JSON: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json

    Minified JSON: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.min.json

    https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies.json