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

103
Vistas
Combining two JavaScript API requests inside of a function

I am very new to JavaScript and as my current assignment, I am to create a simple weather forecast site using openweathermap.org API. The requirements for my assignment dictate that I must be able to fetch weather data by entering only a city name. However, the openweather API requires that the latitude and longitude be included in the request URL. The Forecast API call URL is: https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key} . For this URL, I think I would write:

let forecastApiUrl = 'http://api.openweathermap.org/data/2.5/onecall?lat=' + lat + '&lon=' + lon + '&exclude=minutely&appid={TopSecretApiKey}';

As luck would have it, openweathermap has a GeoCoding API as well! The API call for GeoCoding is: https://api.openweathermap.org/geo/1.0/direct?q={city name}{state code}{country code}&limit={limit}&appid={API key} . I haven't written the URL variable for this yet.

My question is: How do I go about writing the function such that the contents of the GeoCoding API response will be "read" by the Forecast API call, and output my desired weather forecast? This is only my 2nd API exercise, and the only one I've done requiring this additional step. Any advice much appreciated. Please take into consideration that I am an extreme novice.

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This would be better solved with a promise.

You can sync while waiting for your first geocaching API request, and once that's done, it will send the second request to get the weather.

read this

It will look something like this (PSEUDOCODE):

 function fetchGeoData() { return new Promise((resolve, reject) => { //Check if your request was successful, if it was resolve(), else reject() }) } async function fetchWeather() { const geoData = await fetchGeoData(); And now you can just fetch your weather here, the payload would look something like: {lat: geoData.lat, long: getData.long} }

Don't forget to create backups in case any of your requests fail.

about 4 years ago · Santiago Trujillo 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