Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

501
Views
How can I make Axios try with multiple urls and if one of them working then return data

Like the title, I'm working on an app that calls the YouTube APIs but sometimes my app makes too many requests that trigger the API quotas limit and thus making the app stop working due to error on the API server. The solution for this which I found on the Internet is to create multiple API keys and looping through them. But I'm having a headache figuring out how to make my Axios trying multiple API URLs before returning the data. Any tips or tricks on this?

Here is the sample code I tried:

async function getYoutubeVideoSnippet(id) {
  const response = await axios.all([
    axios.get(
      "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=" +
        id +
        "&key=API_KEY"
    ),
    axios.get(
      "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id=" +
        id +
        "&key=API_KEY"
    ),
  ]);
  return response.data;
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't understand exactly what you want to do, but If you want to have many requests and only need one response, You can use Promise.any. For example

async function fetchData () {
   const requests = [
     axios.get('...'),
     axios.get('...'),
   ]
   const response = await Promise.any(requests)
   return response.data
}

With this example, You can receive the first response, but you should be aware that all requests are eventually sent

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!