Weather API

Weather
Beginner

Overview

Get current weather data and forecasts for any location

Integration Guide

Step 1: Get API Key

To use the Weather API, you need to sign up for an account and get an API key.

  1. Visit Weather API Sign Up
  2. Create an account and verify your email
  3. Navigate to your dashboard to find your API key
  4. Copy your API key for use in your application

Step 2: Set Up Your Project

Create the necessary files for your weather application:

  • index.html - The HTML structure
  • styles.css - CSS for styling
  • weather.js - JavaScript for API integration

Step 3: Implement the Code

Copy the following code into your project files:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Weather API Example</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <div class="weather-container">
    <h1>Current Weather</h1>
    <div id="weather-data">
      <p>Loading weather data...</p>
    </div>
    <button id="refresh-btn">Refresh</button>
  </div>
  
  <script src="weather.js"></script>
</body>
</html>

Step 4: Replace the API Key

Replace your_api_key_here in the JavaScript file with your actual API key.

Step 5: Test Your Implementation

Open your HTML file in a browser to test your weather application. You should see the current weather for London (or change the location in the code).

Error Handling

Common Errors

  • 401 Unauthorized: Invalid API key or exceeded quota
  • 400 Bad Request: Invalid location parameter
  • 429 Too Many Requests: Rate limit exceeded

Rate Limiting

The free tier of Weather API allows 1,000,000 calls per month with a rate limit of 1 request per second.

To handle rate limiting:

  • Implement exponential backoff for retries
  • Cache responses when appropriate
  • Monitor your usage in the Weather API dashboard

API Details

Base URL
https://api.weatherapi.com/v1
Authentication
API Key
Documentation
Official Docs

Endpoints

  • GET
    /current.json

    Get current weather data for a location

    Parameters
    • key*
      string - Your API key
    • q*
      string - Location name, IP address, or coordinates
    • aqi
      string - Include air quality data (yes/no)
  • GET
    /forecast.json

    Get weather forecast for a location

    Parameters
    • key*
      string - Your API key
    • q*
      string - Location name, IP address, or coordinates
    • days
      number - Number of days of forecast (1-10)
    • aqi
      string - Include air quality data (yes/no)
    • alerts
      string - Include weather alerts (yes/no)

Bless Network Resources