Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

80
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda