Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback mechanism #90

Open
fawazahmed0 opened this issue Mar 5, 2024 · 5 comments
Open

Fallback mechanism #90

fawazahmed0 opened this issue Mar 5, 2024 · 5 comments

Comments

@fawazahmed0
Copy link
Owner

fawazahmed0 commented Mar 5, 2024

Fallback URL:

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

Pseudo code:
For example, if you want to fetch eur:

Fetch https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.min.json
If above url fails, then try fetching https://latest.currency-api.pages.dev/v1/currencies/eur.min.json
If above url fails, then try fetching https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/eur.json
If above url fails, then try fetching https://latest.currency-api.pages.dev/v1/currencies/eur.json
@bobaikato
Copy link

Whats the difference between eur.min.json vs eur.json?

@fawazahmed0
Copy link
Owner Author

eur.min.json has no white space to reduce file size

@gaganpreetsharma000
Copy link

brother please help.. i am new to programing. just making currency converter.
you have migrated the files to github. I want to use this link https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/jpy.json in my code but i can't. so as per the given instructions i figured out a little bit and i was able to make this link https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/inr.json but at the last of this link i need usd/inr.json Plz help me out

@KerasirovED
Copy link

brother please help.. i am new to programing. just making currency converter. you have migrated the files to github. I want to use this link https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/jpy.json in my code but i can't. so as per the given instructions i figured out a little bit and i was able to make this link https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/inr.json but at the last of this link i need usd/inr.json Plz help me out

@gaganpreetsharma000, have you seen the migration instruction? It's pretty clear.

By the url, https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/inr.json you are fetching data in the rate INR/XXX, where XXX is another currecy from the got JSON, e.g. USD. In that case, one INR costs 0.012070684 USD.

As you need usd/inr, you have to fetch data USD/XXX: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json, where you'll get a cost of one USD in different currencies, and select the needed one from the received JSON, in your case INR.

image

Try

async function getUsdInrRate() {
    // This url will give you currencies UDS/XXX
    const url = 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.min.json'

    // Fetch data and get INR rate
    const inr = await fetch(url)
        .then(response => response.json())
        .then(data => data['usd'].inr)

    console.log(inr)
}

getUsdInrRate()

You'll get current rate

image

Tip

Use min versions of the files to get reduced files (whitespaces deleted), and faster responses, I assume.
Instead of 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json'
Use 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.min.json'
I used the second one in the code

@vandana-khatri8
Copy link

brother please help.. i am new to programing. just making currency converter. you have migrated the files to github. I want to use this link https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/jpy.json in my code but i can't. so as per the given instructions i figured out a little bit and i was able to make this link https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/inr.json but at the last of this link i need usd/inr.json Plz help me out

i face the same issue do you have its solution ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants