Sinatra Service Hands On

Scenario

  • A horoscope web service to allow apps (e.g. a calendar) to place a horoscope into their user interface
  • It has no “user interface”, that is no web site: Just a set of web services
  • Reference: Designing with Class: Heroku, Sinatra, Postgress

Web Service API

GET /fortune/:date/:sign
  • :date -> date for the fortune, e.g. mar-15-2015
  • :sign -> sign, e.g. “scorpio”
  • Returns english language fortune
  • Status 200 unless parameters are invalid
Implementation
  • A database of fortunes
    • migrations
    • seed data
    • gem activerecord
    • gem sinatra-activerecord
  • “config” and “db” folders are not dictated by sinatra
    • db: contains the migrations, seed and db data
    • config: contains database config
  • Sinatra notes
    • Notice “modular” form of a sinatra app
    • Notice use of “shotgun” to auto reload the sinatra app
    • Notice the need for “config.ru”