This Spring Boot project integrates the Weather API from Rapid API and exposes RESTful APIs to retrieve weather forecast data for any city.
This project provides a simple backend server built with Spring Boot that integrates with the Weather API from Rapid API. It includes the following features:
-
Header-based authentication with a random client ID and client secret.
-
Exposes RESTful APIs to get the weather forecast summary and hourly forecast details of any city.
-
Uses
RestTemplate
for making HTTP requests to the Weather API endpoints. -
Project Deployment:
- The project is deployed on Railway app.
- Deployed link: forecasto-production.up.railway.app
Before running this project, make sure you have the following:
- Java Development Kit (JDK) 11 or higher installed.
- Maven installed (if you are not using an IDE that manages dependencies).
application.properties
: Contains configuration properties such as Rapid API host, key, and API URLs.
src/main/java
: Contains Java source code.com.forecasto
: Main package for the project.Forecasto.java
: Main Spring Boot application class.ForecastoConfig
: Contains configuration classes (WeatherApiConfig.java
).ForecastoController
: Contains RESTful controller classes (WeatherController.java
).ForecastoService
: Contains service classes (WeatherApiService.java
).
src/main/resources
: Contains application properties and static resources.application.properties
: Configuration properties file.
- Spring Boot Starter Web: For building web applications with Spring Boot.
- Spring Boot Starter Test: For testing Spring Boot applications (optional).
- Rapid API Java SDK: For integrating with the Weather API from Rapid API.
git clone https://github.com/your-username/your-repo-name.git
cd your-repo-name
- Open the
application.properties
file located insrc/main/resources
and replace the placeholdersyour-rapidapi-host
andyour-rapidapi-key
with your actual Rapid API host and key. - To access the Rapid API, credentials (host and key) must be provided in the properties file.
spring.application.name=Forecasto
rapidApi.host={add-your-host-Name}
rapidApi.key={add-your-key}
rapidApi.url.forecastSummary=https://forecast9.p.rapidapi.com/rapidapi/forecast/
rapidApi.url.hourlyForecast=https://api.openweathermap.org/data/2.5/forecast?q=
openWeatherApi.Key=1204d1db8a4c17b9fc0a1f4902ede7a6
If you are using Maven, run the following command:
mvn clean install
mvn spring-boot:run
Once the project is running, you can access the following endpoints:
-
Forecast Summary:
- Endpoint: /weather/forecastSummary?location=Delhi
- Example API URL: forecasto-production.up.railway.app/weather/forecastSummary?location=Delhi
- Description: Retrieves the forecast summary for a specific location (e.g., Delhi).
-
Hourly Summary:
- Endpoint: /weather/hourlySummary?location=Delhi
- Example API URL: forecasto-production.up.railway.app/weather/hourlySummary?location=Delhi
- Description: Retrieves the hourly forecast summary for a specific location (e.g., Delhi).
- Rapid API Free Tier Limit: Reacting to the free tier limit, you need to provide your Rapid API credentials (host and key) in the properties file for API access.
Please ensure that the Rapid API credentials are correctly configured in the properties file and replace "Delhi" with the desired location when making API requests.
Contributions to this project are welcome. You can contribute by:
- Reporting issues or suggesting improvements through GitHub Issues.
- Forking the repository and creating pull requests for new features or bug fixes.
This project is licensed under the MIT License.
---