A modern weather application built to learn API integration using JavaScript, HTML, and Bootstrap with WeatherAPI.com.
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
- 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
Service: WeatherAPI.com
Plan: Free Trial (ends 10/Sep/25)
Quota: 1 million calls/month
Endpoint: /current.json
- Open
index.html
in a web browser - Enter a location (city, ZIP, coordinates)
- View weather data and explore features
- Toggle dark/light mode with the top-right button
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
- HTML5 - Semantic structure
- CSS3 - Custom properties, animations
- Bootstrap 5 - Responsive framework
- JavaScript ES6+ - Async/await, fetch API
- WeatherAPI.com - Weather data service
// 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);
}
}
- Understanding REST API integration
- Handling asynchronous operations
- Managing API errors gracefully
- Creating responsive, accessible UIs
- Implementing persistent user preferences
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 |
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.
- 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
- 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
- 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)
By building this project, I learned:
-
API Fundamentals
- How to read API documentation
- Understanding request/response cycles
- Working with API keys and authentication
- Handling different response formats
-
Error Handling Strategies
- Network error management
- API rate limiting responses
- Invalid input validation
- User-friendly error messages
-
Asynchronous Programming
- Promise-based programming
- async/await syntax
- Managing loading states
- Concurrent API requests
-
Data Management
- JSON parsing and manipulation
- Data validation and sanitization
- State management in vanilla JavaScript
- Local storage for persistence
-
UI/UX Design
- Creating intuitive interfaces
- Implementing dark mode
- Responsive design principles
- Accessibility best practices
- Basic understanding of HTML, CSS, and JavaScript
- A modern web browser
- Text editor or IDE (VS Code recommended)
- Internet connection for API calls
- Clone or download this repository
- Open the project in your preferred code editor
- Review the code structure to understand the organization
- Open
index.html
in your web browser - Open browser DevTools to monitor API calls and debug
- Examine the API calls in
script.js
- Test different search inputs to see various API responses
- Check the Network tab in DevTools to see actual HTTP requests
- Experiment with error scenarios (invalid locations, network issues)
- Modify the code to add new features or change existing ones
// 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 custom properties for theme switching */
:root {
--primary-color: #4a90e2;
--background-color: #2c2c2611;
}
[data-theme="dark"] {
--primary-color: #5aa3f0;
--background-color: #0f0f0f;
}
- 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
- Query Parameters: How to pass location data to APIs
- Response Structure: Understanding JSON data organization
- Error Codes: HTTP status codes and API-specific errors
- Rate Limiting: Managing API quota and usage
- CORS: Cross-origin requests and browser security
// 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));
- 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
// 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
}
}
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
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';
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
- 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
- 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
This project is open source and available under the MIT License.
- WeatherAPI.com: Weather data provider
- Bootstrap 5: UI framework
- Font Awesome: Icons
- Google Fonts: Typography (Segoe UI fallback)
- JavaScript: JavaScript.info
- APIs: REST API Tutorial
- CSS: CSS Grid Guide
- Bootstrap: Official Bootstrap Docs
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.
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
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
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
Problem: Managing loading states and data visibility
Solution: Created clear state management functions
Key Takeaway: Organize code into small, focused functions
- 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
- 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
โ
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
- WeatherAPI.com Documentation
- MDN Web Docs - Fetch API
- Bootstrap 5 Documentation
- CSS-Tricks - CSS Custom Properties
- 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