@RestController @RequestMapping("/weather") public class WeatherController { private static final String WEATHER_API_URL = "http://api.weatherapi.com/v1/current.json?q={city}&key={apiKey}"; @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public WeatherResponse getWeather(@RequestParam(value = "city") String city, @RequestParam(value = "apiKey") String apiKey) throws ParseException { try { RestTemplate restTemplate = new RestTemplate(); WeatherDto weatherDto = restTemplate.getForObject(WEATHER_API_URL, WeatherDto.class, city, apiKey); assert weatherDto != null; return WeatherService.getWeather(weatherDto); } catch (ParseException e) { throw new ParseException("Error - ", e.getErrorOffset()); } } }