Weather Forecaster is a simple web application that retrieves and displays the current weather forecast based on a provided address. Powered by OpenWeather API and Geocodio API, it provides real-time weather updates and caches results for optimized performance.
A live version of the site is deployed on Heroku:
- Search Weather by Address: Enter any address (U.S. or Canada) to get the current weather details, including temperature, description, and icon
- Error Handling: Handles invalid addresses gracefully with user-friendly messages
- User Interface with Bootstrap: Clean and responsive design powered by Bootstrap for better user experience
- API Usage Limits:
- Caching for Efficiency: Forecast data is cached for 30 minutes based on zip codes to optimize performance and ensure that repeated requests do not unnecessarily consume OpenWeather API calls
- In production, Redis-backed caching ensures consistent performance and scalability across multiple workers
- In development, caching is performed in-memory for simplicity
- Framework: Ruby on Rails
- APIs:
- Frontend: Bootstrap CSS for styling
- Deployment: Heroku
- Cache Backend:
- Production: Redis Cloud (Heroku Add-on) (30MB)
- Development: In-memory caching (64MB)
-
Install dependencies
bundle install
-
Create API Keys
Sign up for free accounts at:
Generate API keys from each service after signing up.
-
Set up environment variables
Create a .env file with the following variables:
GEOCODIO_API_KEY=your_geocodio_api_key OPENWEATHER_API_KEY=your_openweather_api_key
-
Run the server
rails server
-
Access the application
Visit http://localhost:3000 in your browser.
This project uses RSpec for testing. Tests can be run with the following command:
bundle exec rspec
- Search for Weather:
- On the homepage, enter an address (e.g.,
One Apple Park Way, Cupertino, CA 95014
) or a more general location (e.g.,California
orToronto, Canada
). - Note: The address can be either specific or broad (e.g., a street address, city, or state). However, it must be within the US or Canada, as Geocodio only supports these regions.
- Click Get Forecast to view the weather details.
- On the homepage, enter an address (e.g.,
- Caching:
- Results are cached for 30 minutes to enhance speed and limit API requests.
- If you search the same address within the cache period, the app will display the cached result.
- Error Handling:
- If an invalid address is entered, an error message will be displayed asking the user to try again.