Skip to content

Java weather app using Spring and REST API, OpenWeatherMap API integration with fallback mock data

Notifications You must be signed in to change notification settings

tvdxr/weather_app_java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌤️ Weather App Java

A modern, full-stack weather application built with Spring Boot and vanilla HTML/CSS/JavaScript. Features intelligent city name correction, geolocation support, rate limiting, and a beautiful responsive design.

✨ Features

  • 🌍 City Weather Search - Get weather for any city worldwide
  • 📍 Geolocation Support - Use your current location for weather data
  • 🔧 Smart City Correction - Handles typos using Levenshtein distance algorithm
  • 📱 Responsive Design - Works on desktop and mobile devices

🚀 Quick Start

Prerequisites

Setup

  1. Clone the repository

    git clone https://github.com/tvdxr/weather_app_java.git
    cd weather_app_java/demo
  2. Configure API Key

    Option A: Using application-local.properties (Recommended for development)

    # Copy the example configuration
    cp src/main/resources/application.properties.example src/main/resources/application-local.properties
    
    # Edit application-local.properties and add your API key
    weather.api.key=YOUR_OPENWEATHERMAP_API_KEY_HERE

    Option B: Using Environment Variable

    # Set environment variable (Windows)
    set WEATHER_API_KEY=your_api_key_here
    
    # Set environment variable (Linux/Mac)
    export WEATHER_API_KEY=your_api_key_here
  3. Run the application

    mvn spring-boot:run
  4. Open your browser

    Navigate to http://localhost:8080

🏗️ Architecture

Backend (Spring Boot)

  • WeatherService - Core business logic with API integration
  • WeatherController - REST API endpoints (/api/weather/*)
  • Smart City Correction - Levenshtein distance algorithm for typos

Frontend (Vanilla Web)

  • Responsive HTML5 - Semantic structure with accessibility
  • Modern CSS3 - Grid/Flexbox layout with gradient themes
  • ES6 JavaScript - Fetch API, async/await, geolocation

API Endpoints

  • GET /api/weather/{city} - Get weather by city name
  • GET /api/weather/coordinates?lat={lat}&lon={lon} - Get weather by coordinates

🔧 Configuration

The application can be configured through application.properties or environment variables:

# Server Configuration
server.port=8080

# API Configuration  
weather.api.key=${WEATHER_API_KEY:}
weather.api.url=https://api.openweathermap.org/data/2.5/weather


## 🙏 Acknowledgments

- [OpenWeatherMap](https://openweathermap.org/) for the weather API
- [Spring Boot](https://spring.io/projects/spring-boot) for the awesome framework

---

About

Java weather app using Spring and REST API, OpenWeatherMap API integration with fallback mock data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published