Skip to content

๐ŸŒค๏ธ Modern weather app built with JavaScript, Bootstrap & WeatherAPI - Learning project for API integration, async programming & responsive design

License

Notifications You must be signed in to change notification settings

kanishkaGayan/JS-Weather-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Weather App - API Learning Project

A modern weather application built to learn API integration using JavaScript, HTML, and Bootstrap with WeatherAPI.com.

๐Ÿ“š Learning Focus

This project demonstrates:

  • API Integration: HTTP requests with fetch API
  • Async JavaScript: Promise handling and error management
  • DOM Manipulation: Dynamic UI updates
  • Responsive Design: Mobile-friendly interface
  • Dark Mode: Theme switching with localStorage

๐ŸŒŸ Features

  • Real-time weather data for any location
  • Dark/Light mode toggle
  • Responsive design (desktop, tablet, mobile)
  • Search by city, ZIP code, coordinates
  • Geolocation support
  • Comprehensive weather details (temperature, humidity, wind, UV index, etc.)
  • Error handling and offline detection

๐Ÿ”‘ API Information

Service: WeatherAPI.com
Plan: Free Trial (ends 10/Sep/25)
Quota: 1 million calls/month
Endpoint: /current.json

๐Ÿš€ Screen Shots

  1. image
  2. image
  3. image

๐Ÿš€ Quick Start

  1. Open index.html in a web browser
  2. Enter a location (city, ZIP, coordinates)
  3. View weather data and explore features
  4. Toggle dark/light mode with the top-right button

๐Ÿ“ File Structure

js weather/
โ”œโ”€โ”€ index.html      # Main HTML structure
โ”œโ”€โ”€ style.css       # CSS with dark mode & responsive design
โ”œโ”€โ”€ script.js       # JavaScript with API integration
โ””โ”€โ”€ README.md       # Project documentation

๐Ÿ› ๏ธ Key Technologies

  • HTML5 - Semantic structure
  • CSS3 - Custom properties, animations
  • Bootstrap 5 - Responsive framework
  • JavaScript ES6+ - Async/await, fetch API
  • WeatherAPI.com - Weather data service

๐Ÿ“Š API Usage Example

// Basic API call structure
const API_KEY = 'your-key';
const BASE_URL = 'https://api.weatherapi.com/v1';

async function fetchWeather(location) {
    try {
        const response = await fetch(`${BASE_URL}/current.json?key=${API_KEY}&q=${location}`);
        const data = await response.json();
        displayWeather(data);
    } catch (error) {
        handleError(error);
    }
}

๐ŸŽฏ Learning Outcomes

  • Understanding REST API integration
  • Handling asynchronous operations
  • Managing API errors gracefully
  • Creating responsive, accessible UIs
  • Implementing persistent user preferences

๐Ÿ”ง Common Issues

Issue Solution
Location not found Try different search formats
Network error Check internet connection
API key error Verify key is valid
Quota exceeded Wait for monthly reset

๏ฟฝ Project Status

Created: August 27, 2025
Status: Learning Project - Active
Purpose: Educational API integration practice


This project represents learning modern web development and API integration concepts through hands-on practice.

๐Ÿ› ๏ธ Technologies & Skills Practiced

Frontend Technologies

  • HTML5: Semantic structure and accessibility
  • CSS3: Custom properties, flexbox, grid, animations
  • Bootstrap 5: Responsive design and UI components
  • JavaScript ES6+: Modern JavaScript features and syntax

API Integration Skills

  • Fetch API: Making HTTP requests
  • Promise Handling: async/await patterns
  • Error Management: Try-catch blocks and user feedback
  • Data Transformation: Processing JSON responses
  • Rate Limiting: Understanding API quotas and limits

Development Practices

  • Responsive Design: Mobile-first approach
  • Accessibility: ARIA labels and keyboard navigation
  • Local Storage: Persisting user preferences
  • Code Organization: Modular JavaScript structure
  • Version Control: Git workflow (if applicable)

๐ŸŽฏ Learning Outcomes

By building this project, I learned:

  1. API Fundamentals

    • How to read API documentation
    • Understanding request/response cycles
    • Working with API keys and authentication
    • Handling different response formats
  2. Error Handling Strategies

    • Network error management
    • API rate limiting responses
    • Invalid input validation
    • User-friendly error messages
  3. Asynchronous Programming

    • Promise-based programming
    • async/await syntax
    • Managing loading states
    • Concurrent API requests
  4. Data Management

    • JSON parsing and manipulation
    • Data validation and sanitization
    • State management in vanilla JavaScript
    • Local storage for persistence
  5. UI/UX Design

    • Creating intuitive interfaces
    • Implementing dark mode
    • Responsive design principles
    • Accessibility best practices

๐Ÿš€ Getting Started (Learning Mode)

Prerequisites

  • Basic understanding of HTML, CSS, and JavaScript
  • A modern web browser
  • Text editor or IDE (VS Code recommended)
  • Internet connection for API calls

Setup Instructions

  1. Clone or download this repository
  2. Open the project in your preferred code editor
  3. Review the code structure to understand the organization
  4. Open index.html in your web browser
  5. Open browser DevTools to monitor API calls and debug

Learning Exercise

  1. Examine the API calls in script.js
  2. Test different search inputs to see various API responses
  3. Check the Network tab in DevTools to see actual HTTP requests
  4. Experiment with error scenarios (invalid locations, network issues)
  5. Modify the code to add new features or change existing ones

๐Ÿ” Code Walkthrough

API Integration (script.js)

// Key learning concepts demonstrated:

// 1. API Configuration
const API_KEY = 'your-api-key';
const BASE_URL = 'https://api.weatherapi.com/v1';

// 2. Async/Await Pattern
async function fetchWeatherData(location) {
    try {
        const response = await fetch(`${BASE_URL}/current.json?key=${API_KEY}&q=${location}`);
        const data = await response.json();
        // Handle success
    } catch (error) {
        // Handle errors
    }
}

// 3. Error Handling
function handleFetchError(error) {
    // Different error types and user-friendly messages
}

CSS Variables and Theming (style.css)

/* CSS custom properties for theme switching */
:root {
    --primary-color: #4a90e2;
    --background-color: #2c2c2611;
}

[data-theme="dark"] {
    --primary-color: #5aa3f0;
    --background-color: #0f0f0f;
}

๐Ÿ”ง API Configuration & Learning Notes

WeatherAPI.com Setup

  • Base URL: https://api.weatherapi.com/v1
  • Endpoint Used: /current.json
  • Authentication: API key in query parameter
  • Rate Limits: 1 million calls/month (free tier)
  • Trial Period: Until 10/Sep/25

Important API Concepts Learned

  1. Query Parameters: How to pass location data to APIs
  2. Response Structure: Understanding JSON data organization
  3. Error Codes: HTTP status codes and API-specific errors
  4. Rate Limiting: Managing API quota and usage
  5. CORS: Cross-origin requests and browser security

Sample API Request

// Example API call structure
const url = `${BASE_URL}/current.json?key=${API_KEY}&q=${location}&aqi=yes`;
fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error(error));

Common API Errors and Solutions

  • 401 Unauthorized: Check API key validity
  • 400 Bad Request: Verify location format
  • 403 Forbidden: API key might be over quota
  • Network Errors: Check internet connection

๐Ÿ“Š Data Handling Examples

Weather Data Structure

// Typical API response structure
{
    "location": {
        "name": "London",
        "region": "City of London, Greater London",
        "country": "United Kingdom",
        "localtime": "2025-08-27 14:30"
    },
    "current": {
        "temp_c": 22.0,
        "condition": {
            "text": "Partly cloudy",
            "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png"
        },
        "wind_kph": 15.5,
        "humidity": 65,
        // ... more weather data
    }
}

Error Handling

The app includes comprehensive error handling for:

  • Network errors: Internet connection issues
  • Invalid locations: Non-existent or misspelled locations
  • API errors: Rate limiting, authentication issues
  • Geolocation errors: Permission denied or unavailable
  • Offline status: Automatic detection and user notification

Customization

Changing the API Key

If you need to use a different API key, update the API_KEY constant in script.js:

const API_KEY = 'your-new-api-key-here';

Adding Features

The modular structure makes it easy to add new features:

  • Forecast data: Extend with /forecast.json endpoint
  • Weather alerts: Add /alerts.json integration
  • Historical data: Include /history.json functionality
  • Marine data: Integrate /marine.json for coastal areas

Performance

  • Optimized loading: Minimal external dependencies
  • Efficient API calls: Single request per search
  • Cached data: Smart refresh functionality
  • Lazy loading: Icons and images loaded on demand

Security

  • HTTPS only: All API calls use secure HTTPS
  • Input validation: Location input is properly sanitized
  • Error boundaries: Graceful handling of unexpected errors
  • No sensitive data: No user data stored locally

License

This project is open source and available under the MIT License.

Credits

  • WeatherAPI.com: Weather data provider
  • Bootstrap 5: UI framework
  • Font Awesome: Icons
  • Google Fonts: Typography (Segoe UI fallback)

Learning Resources


๐Ÿ“„ Project Information

Created: August 27, 2025
Last Updated: August 27, 2025
Status: Learning Project - Active Development
API Trial End: September 10, 2025

Purpose: Educational project for learning API integration, asynchronous JavaScript, and modern web development practices.

License: Open source for educational purposes


This project represents my journey in learning web development and API integration. Each feature was implemented as a learning exercise to understand modern web development practices.

๐ŸŽ“ Learning Challenges & Solutions

Challenge 1: Understanding Asynchronous JavaScript

Problem: Initially struggled with Promise handling and async operations
Solution: Practiced with async/await syntax and proper error handling
Key Takeaway: Always handle both success and error cases in API calls

Challenge 2: Managing API Errors Gracefully

Problem: Raw API errors were confusing for users
Solution: Created custom error handling with user-friendly messages
Key Takeaway: Good UX requires translating technical errors to human language

Challenge 3: Responsive Design with Dynamic Content

Problem: Weather cards didn't look good on all screen sizes
Solution: Used CSS Grid and Flexbox with responsive breakpoints
Key Takeaway: Test on multiple devices during development

Challenge 4: State Management

Problem: Managing loading states and data visibility
Solution: Created clear state management functions
Key Takeaway: Organize code into small, focused functions

๐Ÿ”ฎ Future Learning Goals

Next API Skills to Learn

  • Forecast APIs: Multi-day weather predictions
  • Pagination: Handling large datasets
  • Authentication: OAuth and advanced auth methods
  • WebSockets: Real-time data streaming
  • GraphQL: Modern API query language
  • API Testing: Postman and automated testing

Code Improvements to Implement

  • TypeScript: Add type safety
  • Build Tools: Webpack or Vite setup
  • Testing: Unit and integration tests
  • PWA Features: Service workers and offline support
  • Performance: Code splitting and optimization

๐Ÿ“ Personal Learning Notes

What Worked Well

โœ… Breaking down the project into small, manageable pieces
โœ… Using browser DevTools to debug API calls
โœ… Reading API documentation thoroughly before coding
โœ… Implementing error handling from the beginning
โœ… Testing with various input types and edge cases

Resources Used

๐Ÿค Acknowledgments

  • WeatherAPI.com for providing the weather data service
  • Bootstrap Team for the responsive framework
  • Font Awesome for the beautiful icons
  • MDN Web Docs for excellent JavaScript documentation

About

๐ŸŒค๏ธ Modern weather app built with JavaScript, Bootstrap & WeatherAPI - Learning project for API integration, async programming & responsive design

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published