Weather API Learning Activity

Learning Objectives:

  1. Understand the concept of APIs and their role in web applications
  2. Learn how to use multiple APIs in a single application
  3. Practice making API requests and handling responses
  4. Gain experience in parsing and displaying data from different APIs
  5. Understand common API errors and how to troubleshoot them

Instructions:

  1. Get a free API key from OpenWeatherMap:
    • Sign up for a free account
    • Go to your account page and copy your API key
    • Note: It may take up to 2 hours for a new API key to become active
  2. Paste your OpenWeatherMap API key in the input field below
  3. Enter a city name and click "Get Weather"
  4. Observe the API responses and how the data is displayed
  5. If there's an error, check the debug information and troubleshooting section below


Debug Information:


    

Troubleshooting API Issues:

  1. Verify that you've entered the OpenWeatherMap API key correctly. It should be a long string of letters and numbers.
  2. Check if your OpenWeatherMap API key has been activated. New keys can take up to 2 hours to become active.
  3. Ensure you're not exceeding the rate limits for the Nominatim API (1 request per second) or your OpenWeatherMap plan.
  4. If the city isn't found, try adding the country name (e.g., "London, UK" instead of just "London").

What's happening?

When you click "Get Weather", this application makes calls to two different APIs:

  1. First, it calls the OpenStreetMap Nominatim API to convert the city name into latitude and longitude coordinates. This API is free and doesn't require an API key.
  2. Then, it uses these coordinates to fetch current weather data from the OpenWeatherMap Weather API. This API requires the API key you provided.

The weather data for the specified city is then displayed on this page.

If there's an error, check the debug information and troubleshooting section for details on what might be wrong and how to fix it.