The weather service provides an API for retrieving weather data. It includes three main endpoints, each of which performs a specific function. Below you will find a description of each endpoint, along with a link to the Swagger documentation for more information.
- Get a list of the last 10 requested cities.
- URL: http://localhost:8080/weather
- Method: GET
- Description: This endpoint lists the cities requested by the user. This is needed to retrieve information about deleting data for a city.
- Get weather by city
- URL: http://localhost:8080/weather/getByCity?city=cityname
- Method: GET
- Parameters:
- city (string, required) - the name of the city for which you want to retrieve weather data.
- Description: This endpoint allows the user to retrieve current weather conditions for the specified city. The response contains detailed weather information relevant to the requested city. If an invalid city name is passed, the service may return an error message.
- Deleting City Data
- URL: http://localhost:8080/weather/removeCity?city=cityname
- Method: DELETE
- Parameters:
- city (string, required) - the name of the city whose data should be deleted.
- Description: This endpoint allows the user to delete weather information stored for the specified city.
For more detailed information about available endpoints, their parameters, and service features, you can use the Swagger documentation user interface:
- Swagger UI: http://localhost:8080/docs/swagger-ui/index.html
The application supports two modes that determine how weather data is retrieved. The available modes are listed below:
- Description: In this mode, the application retrieves weather data as needed, when data is only required upon user request, for example, when the user enters a city name. In this case, the application sends a request to the API and returns the current weather data.
- Description: In POLLING mode, the application automatically and periodically requests weather data every 10 seconds.
For the application to function correctly, you must specify certain parameters when launching it.
- OpenWeatherMap API Key
- Parameter: --openweathermap.api.key
- Description: This parameter specifies the API key that must be obtained from the OpenWeather platform. It allows the application to authenticate when sending API requests and receive up-to-date weather data. Be sure to replace the empty string with your valid API key.
- Service Operation Mode
- Parameter: --openweathermap.api.mode
- Description: This parameter determines the application's operation mode.
- Server Port
- Parameter: --server.port
- Description: This parameter sets the port on which your Spring Boot application will run. By default, Spring Boot uses port 8080, but if it is busy or you need to use a different port (for example, for deployment in a multi-application environment), you can change it to any available value. Make sure the specified port does not conflict with other services on this machine.
An example command to start your application with the required parameters looks like this:
java -jar weather-api-0.0.1-SNAPSHOT.jar --openweathermap.api.key="your_api_key" --openweathermap.api.mode=POLLING --server.port=8090