The weather-service
project is a Rails-based application that provides weather information by utilizing the Weatherbit API. The service fetches current temperature data based on city and country parameters and renders the data in a JSON format.
- Fetch current temperature data based on city and country.
- Uses caching to efficiently serve repeated requests.
- Comprehensive error messages for invalid or missing parameters.
- Ruby version: (Specify the version you're using, e.g.,
3.2.2
) - Rails version: (Specify the version you're using, e.g.,
7.0.8
)
-
Clone the repository:
git clone git@github.com:AFU92/weather-service.git cd weather-service
-
Install the necessary gems:
bundle install
-
Set up the environment variables:
Create a .env file in the root directory of the project and set up your Weatherbit API configurations:
WEATHERBIT_BASE_URL=[YOUR_WEATHERBIT_BASE_URL] WEATHERBIT_API_KEY=[YOUR_WEATHERBIT_API_KEY]
Replace [YOUR_WEATHERBIT_BASE_URL] and [YOUR_WEATHERBIT_API_KEY] with your actual Weatherbit URL and API key respectively.
-
Start the Rails server:
rails s
To fetch current weather data for a specific city and country:
GET /current?city=[CITY_NAME]&country=[COUNTRY_CODE]
Example:
GET /current?city=Raleigh&country=US
Response:
{
"temperature": 22.5,
"apparent_temperature": 23.0
}
The service uses Rails caching to store weather data for 10 minutes, reducing the need for repeated API calls and improving response times for frequently requested locations.