List cities and get the one where it is the hottest today
For demo and educational purposes only! Do not use in production!
Weather data is taken from https://www.metaweather.com/api/
Please, contact metaweather owner before you start using it.
Just start App class in your IDE or from command line.
Or, using Maven:
mvn spring-boot:run
Make sure Maven is installed and your JDK is in your JAVA_HOME variable.
There are two end points:
Accepts a list of cities (ex: berlin,amsterdam,pairs) and returns a HotCity, which contains city name and the temperature. Ignores cities, which cannot be found. If no cities are found, HTTP response 404 is returned.
Example: http://localhost:8080/api/weather/berlin,paris,amsterdam
Uses Thymeleaf to render two pages: index.html with the form to enter the list and city.html, which renders the hottest city.
Example: http://localhost:8080/weather
It is quite standard approach with three layers:
- Web (HotCityResource.java)
- Business logic (WatherService.java)
- External service to get the weather (ExternalWeatherGateway.java)
- We throw a SomeCitiesNotFoundException when no cities are found and handle it with RestExceptionHandler.java
- All beans are configured in ExternalWeatherGatewayConfig.java, which can be improved, since now it contains some other bean definitions, which are not relevant for the Gateway.
- Since external weather service is HTTPS, we disable some security checks in CustomRestTemplateCustomizer.java
- We print each request/response to console, by intercepting in CustomClientHttpRequestInterceptor.java
- The
telran.hotcities.clientmodelpackage contains web model classes for the servlet.
- Increase test coverage
- Clean up here and there
- Add more features
- Add css to the html pages