This is a Spring Boot application that provides current weather data and weather forecasts by consuming the OpenWeatherMap API.
- Get Current Weather: Fetches current weather data for a given city.
- Get Weather Forecast: Fetches a weather forecast for the next few days for a given city.
The application exposes two main endpoints:
-
/weather?city={cityName}
- Fetches the current weather for the given city.
- Example:
/weather?city=Thessaloniki
- Response:
"Current Weather: City: Thessaloniki, Temperature: 22.5°C, Weather: Clear"
-
/forecast?city={cityName}
- Fetches the weather forecast for the next few days for the given city.
- Example:
/forecast?city=Thessaloniki
- Response: (Shows forecast for 2 or more upcoming days)
"Forecast: City: Thessaloniki, Day 1: 21.5°C, Clear Sky, Day 2: 20.2°C, Clouds"
- The application uses
RestTemplate
to make GET requests to the OpenWeatherMap API. - JSON responses are parsed using
Jackson
'sObjectMapper
to extract and display relevant weather information. - The API key is securely stored in
application.properties
and injected into the service using Spring's@Value
annotation.
-
Clone the repository:
git clone https://github.com/your-repo/weather-app.git
-
Open the project in your preferred IDE (e.g., IntelliJ, Eclipse, or VS Code).
-
Add your OpenWeatherMap API Key:
-
Add your API key to the
application.properties
file insrc/main/resources/
:openweathermap.api.key=YOUR_API_KEY_HERE
-
-
Build and run the project:
mvn spring-boot:run
-
Access the application by calling the REST endpoints via Postman or your browser:
- For current weather:
http://localhost:8080/weather?city=Thessaloniki
- For weather forecast:
http://localhost:8080/forecast?city=Thessaloniki
- For current weather:
- Spring Boot
- Spring Web
- Jackson (for JSON parsing)
- OpenWeatherMap API