Fetching Weather Data from an API

Fetching Weather Data from an API

At the heart of our app is real-time weather data. To get it, we use the OpenWeatherMap API and fetch data with a custom service inside WeatherService.js.

const getWeatherByCity = async (city) => {
  const response = await fetch(`${BASE_URL}?q=${city}&appid=${API_KEY}&units=metric`);
  const data = await response.json();
  return data;
};

We use fetch() to make a GET request to the OpenWeatherMap API. The response contains information like temperature, wind, weather type, and more — which we pass to the WeatherCard to display beautifully. This setup ensures your app updates in real-time when a user searches for any city!