What is Sinatra?

What is Sintra?

  • A ruby library
  • Easiest way to create a simple web server
  • Much smaller and easy to understand than rails (also less powerful)
  • What is Sinatra according to their own Sinatra Intro

Components of a Sinatra app

  • Single main ruby program
  • Routing
    • One method for each “route”
    • Rendering of Views
    • Nice pattern matching to generalize similar routes
    • At the end of the method, either render html, json, or redirect
    • Each of the route methods are “kind of like” a controller
  • Data
    • Sinatra doesn’t do anything special about working with the database
    • Whatever database access you prefer will work
    • Our examples use ActiveRecrord as a library to interface with the database
    • But there are other ones that work just as well
    • Typical design
      • encapsulates the data access in a class
      • one class for each table or entity
      • often referred to as a model class
  • Views
    • Erb is a very common templating language
    • Look at ERB Cribsheet
    • They are what is generated at the end of the route method
    • In addition to erb there are tons of others
    • What they have in common: they all generate data (in the end) that is returned as the result of an HTTP request