Bonus Homework
Servers! Servers, everywhere!
- Create a new directory in
05_ruby101/your_name/calledsinatra_reps - Create a brand new, small Sinatra app.
- Write a simple Sinatra app with a
Gemfile,config.ru, andapp.rb - Inside of your
app.rb, you need to create a few routes...- '/' - This should return a Hash turned into JSON with the following keys:
:nameand:message - '/about' - this should return a Hash turned into JSON with the following keys:
:about,:age,:favourites - '/contact' - this should return a Hash turned into a JSON with the following keys:
:name,:email, and:thanks
- '/' - This should return a Hash turned into JSON with the following keys:
- Test and verify these routes render JSON in the browser.
- BONUS Add ERB views and then create a new
/views/json_test.erb. Map it to arouterand call each API call using$.getJSONor$.ajaxto render the content usingconsole.logor whatever else you choose.