A simple Rack web app for querying and rendering data from the OpenWeatherMap API.
-
Sign up with OpenWeatherMap here
-
Get an API key here
-
Git clone rack-weather
-
Make an env.rb file at the root directory
-
Define your API key in env.rb like so:
ENV['API_KEY] = 'your-api-key'
-
Install the gems
bundle install
-
Start the server
bundle exec rackup --port 3000 --host 0.0.0.0
There are currently two urls for querying weather data:
/weather/:city/:country
/weather-data/:city/:country
The first route displays HTML using Trailblazer's cells gem
The 'weather-data' route displays the JSON response
Examples:
localhost:3000/weather/London/uk
localhost:3000/weather-data/London/uk
Many thanks to this great Rack Tutorial
Also to this Sitepoint article on using Trailblazer cells