Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

75
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda