Java-based weather API that fetches and returns weather data from a third party API.
Java Weather APi is a weather API that fetches and returns weather data from Visual Crossing's API. It uses Redis for in-memory caching and Jedis as the client. This project is designed to explore and practice working with the third party APIs, caching and environment variables in Java.
- Java 21.0.6 LTS
- Redis 7.4.3
- Real-Time Weather Data: Fetch up-to-date weather information for any location.
- Location-Based Queries: Retrieve weather details by specifying the desired location in the query parameter.
- Caching for Faster Responses: Utilizes Redis caching to store weather data temporarily.
- Rate Limiting: Implements rate limiting to prevent excessive API calls.
- JSON Responses: Returns structured JSON data, making it easy to integrate with front-end applications or other systems.
- Customizable: Easily configurable API key and Redis connection via environment variables.
To run this API, you’ll need:
- Java: Version 21 or higher
- Maven: Version 3.x
- Redis: Version 7.4 or higher
How to install:
-
Clone the repository
git clone https://github.com/krisnaajiep/java-weather-api.git
-
Change the current working directory
cd java-weather-api
-
Build the project
mvn clean package
-
Copy the JAR file from the target/ directory
cp target/java-weather-api-1.0-SNAPSHOT.war weather-api.war
-
Set environment variables
# Visual Crossing API Key export API_KEY=[your_visualcrossing_api_key] # Redis connection settings export REDIS_HOST=localhost export REDIS_PORT=6379 export REDIS_USERNAME=default # optional export REDIS_PASSWORD=[your_password] # optional export REDIS_DATABASE=0 # optional
-
Run the JAR file
java -jar weather-api.jar
Access the endpoint with the location query parameter.
http://localhost:8080?location=[location]
Project is: complete.
This project was inspired by roadmap.sh.
This project is licensed under the MIT License—see the LICENSE file for details.