This application retrieves weather information from https://openweathermap.org/ for given city, calculates daily and nightly averages of temperatures and average pressure for next three days from today as per below--
- Average of daily (06:00 – 18:00) and nightly (18:01 – 05:59) temperatures in Celsius for the next 3 days from today’s date.
- Average of pressure for the next 3 days from today’s date.
This is a spring-boot application with Maven. Following are the ways to run the application--
- Open this application with Eclipse IDE (Preferably Spring Tool Suite) and run as Spring-Boot app.
- Navigate to Project's root directory where pom.xml file is located. Then run
mvn spring-boot:run
command.
- Application has Controller and Service layar. I've created a
RestController
with nameWeatherController.java
that exposes/data
endpoint to get the required data. Data is returned inJSON
format. Service layer consists of a class namedWeatherServiceImpl.java
. Spring'sRestTemplate
bean is injected in this service class to retrieve data from https://openweathermap.org/. WeatherConfiguration.java
is a configuration class. Beans are created in this class.application.properties
file is used to set default port of application to8085
and application context is set to/weather
. Application is accessible via http://localhost:8085/weather/data?city={cityName} link- eg: http://localhost:8085/weather/data?city=London
- For centralized exception handling and to return appropriate status codes,
GlobalExceptionHandler.java
ControllerAdvice
is created. This returnsErrorInfo
Object whenever exception is raised.