๐ŸŒค๏ธ

Weather App

๐Ÿง‘โ€๐Ÿณ Cookโฑ๏ธ 25 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขJSON API Fetch completed
  • โ€ขBasic React

What you'll build

A weather application with React that consumes the OpenWeatherMap API. You'll be able to search any city and see current temperature, humidity, weather condition and weather icons in real-time. You'll learn to work with external APIs, handle API keys securely, and display dynamic data in a responsive interface.


Recommended API

OpenWeatherMap - Free up to 1000 calls/day


Step 1: Get API Key

  1. Create account at openweathermap.org
  2. Go to API Keys
  3. Copy your key

Step 2: Ask an AI for the app

I need a weather app in React that:
- Searches city by name
- Shows temperature, humidity, condition
- Uses OpenWeatherMap API
- Has weather icons
- Is responsive
- Uses Tailwind CSS

The API key comes from VITE_WEATHER_API_KEY.

Give me the complete code.

Step 3: Configure the key

Create .env:

VITE_WEATHER_API_KEY=your-api-key

Typical code

const API_KEY = import.meta.env.VITE_WEATHER_API_KEY

async function getWeather(city: string) {
  const res = await fetch(
    `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`
  )
  return res.json()
}

If something failed

ErrorCauseSolution
401Invalid API keyCheck the key
404City not foundCheck the name
CORSDirect callUse proxy or backend

Next step

โ†’ Web Calculator โ€” UI logic