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

73
Views
Request to API and waiting to answer

I need to send GET request username=alison&date=2021 to file file.phpand send requests every 200 ms if I don't get one of two possible responses "yes" or "no", resend request needed to get right answer no blank and not error.

If get "yes" "no" do functions. when receiving responses, perform different actions

  1. function after receiving yes
  2. function after receiving no
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm not 100% sure what you're asking for here, but here is my method based on my own interpretation of your question using a call from GitHub's API. We are using fetch to pull the data. Our .then is our resolve, and our .catch is our reject.

const url = 'https://api.github.com/users'

const callApi = function(fetchUrl){
    fetchUrl = url
    fetch(fetchUrl)
        .then(response=>{
            return response.json(); // Turn data to JSON
        })
        .then(data=>{ // If it was successful, this below will run
            console.log(data) // Do whatever you want with the data from the API here
        })
        .catch(err=>{ // If it was unsuccessful, this below will run
            console.log(err); // Console log the error
            setTimeout(callApi(url), 200); //If it failed, try again in 200ms
        })
}

callApi(url) // Initial function call

Some things to note: If you're using an API that limits the number of calls you can make in a day/month, this will eat up through those allotted requests really quickly.

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!