SlideShare a Scribd company logo
microframework
About Me  Nick Zalabak Slides and code  examples for this presentation:  git@github.com:techwhizbang/sinatra_slideshow.git git@github.com:techwhizbang/sinatra_slideshow_code.git  My Blog: http://techwhizbang.com Twitter: @techwhizbang
Compelling Reasons  Sinatra is a “microframework” built on Rack  Easy, practical, go fast!  Made with extensibility in mind  Not crufty or bloated like larger web frameworks  Small memory footprint as compared to other frameworks  On par performance-wise to other frameworks  Works well with many web servers  Works great with JRuby
Sinatra 101  Sinatra is more DSL atop Rack than your typical “framework”  DSL Configuration  DSL Routing  Works with many popular template/view libraries  Has before and after filters similar to Rails  Handles all typical response codes and mime types nicely  Easy testing with popular test frameworks/libraries
Project Layout  There is no set project layout per se  Use best practices and judgment  Nobody likes a “fiddly little snowflake app”
Configuration  Sinatra is configurable  “Out of box” settings are usually OK enable/disable are often overlooked set RACK_ENV=dev|test|prod
Sessions  Surprise! Sessions are off by default  Default cookie based sessions via Rack  Memory? Rack::Session::Pool  Distributed? Rack::Session::Memcache
Cookies response.set_cookie(“viewed_products”, “1,2,3”) reponse.set_cookie(“viewed_products”, [1,2,3]) reponse.delete_cookie(“viewed_products”) request.cookies[“viewed_products”]
Serving css, js, etc   By default Sinatra serves from ‘public’  public, root, views are configurable  use Rack::Static when not standalone
Routing  It’s as simple as  GET, POST,  PUT, DELETE
Templating Erb, HAML, Sass, Erubis, Builder support erb :template, sass :template, etc  Named templating  Inline templating
Filters  Rails inspired before/after filters similar
Helpers  Can be used in templates and controllers
Database Connectivity  “Roll your own” strategy  Connections  Migrations  Extensions sinatra-activerecord sinatra-mongo sinatra-sequel
Load your Rake tasks  Load your own Rake tasks
Caching Gems & Extensions sinatra-cache  rack-cache
Logging  Use a plain Ruby logger sinatra-logger extension
Testing Sinatra  gem rack-test  include Rack::Test::Methods last_response variable provides access to	response body, headers, status, etc last_request variable provides access to host, 	cookies, referrer, params, post?, get?, delete?, 	put?, path, etc
Ways to ‘start’ Sinatra  Basic standalone mode  ruby basic_startup.rb Use a Rackup file - config.ru thin -s 2 -C config.yml-R config.ru start
If Sinatra were a gateway drug… It would lead to Rack
Handy Rack Middlewarez  rack-contrib  rack-throttle  rack-bug  rack-flash  warden  See for yourself and search “rack” on GitHub
Sinatra + Bundler  Get the bundler gem  bundle init  Edit your Gemfile  Add Bundler.setup
Code Counter Sinatra lines of code for tests? 3685 Sinatra actual lines of library code?  2248 Rails 2.3.x  approx 156000
Load testing Sinatra  How does it perform under load? Sinatra is thread safe (try w/JRuby)
Sinatra + Jruby + Warbler jruby –S gem install warbler mkdirconfig  warble config  Check config/warble.rb
Sinatra on Heroku  Version your app with Git(hub) (git init)  Use Bundler or .gems file to manage Gems sudo gem install heroku heroku create git push heroku master  See your gems installed in the terminal  It really is that easy! http://stormy-earth-60.heroku.com/products
Sinatra in Action GitHubresque gem Github Watchtower Heroku: processing background jobs  Cafepress: internal RESTful services
Q&A

More Related Content

Similar to Sinatra

Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
vvatikiotis
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
Deepak Chandella
 
Mahout Introduction BarCampDC
Mahout Introduction BarCampDCMahout Introduction BarCampDC
Mahout Introduction BarCampDC
Drew Farris
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
ssusercd195b
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
Michael Pirnat
 
Why Sun for Drupal?
Why Sun for Drupal?Why Sun for Drupal?
Why Sun for Drupal?
smattoon
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
Leo Zhou
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
MeriamLachkar1
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Udaya Kiran
 
Dev8d Apache Solr Tutorial
Dev8d Apache Solr TutorialDev8d Apache Solr Tutorial
Dev8d Apache Solr Tutorial
Sourcesense
 
Sinatra
SinatraSinatra
Sinatra
kevinreiss
 
Drupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, ScalingDrupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, Scaling
smattoon
 
Serverless on OpenStack with Docker Swarm, Mistral, and StackStorm
Serverless on OpenStack with Docker Swarm, Mistral, and StackStormServerless on OpenStack with Docker Swarm, Mistral, and StackStorm
Serverless on OpenStack with Docker Swarm, Mistral, and StackStorm
Dmitri Zimine
 
Sinatra
SinatraSinatra
WebNano - Ideas for Web Frameworks
WebNano - Ideas for Web FrameworksWebNano - Ideas for Web Frameworks
WebNano - Ideas for Web Frameworks
guestf89f9cb
 
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
Databricks
 
Drupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from SunDrupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from Sun
smattoon
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
Ngoc Dao
 

Similar to Sinatra (20)

Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
 
Capybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using rubyCapybara and cucumber with DSL using ruby
Capybara and cucumber with DSL using ruby
 
Mahout Introduction BarCampDC
Mahout Introduction BarCampDCMahout Introduction BarCampDC
Mahout Introduction BarCampDC
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Why Sun for Drupal?
Why Sun for Drupal?Why Sun for Drupal?
Why Sun for Drupal?
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber       Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
Behavioural Testing Ruby/Rails Apps @ Scale - Rspec & Cucumber
 
Dev8d Apache Solr Tutorial
Dev8d Apache Solr TutorialDev8d Apache Solr Tutorial
Dev8d Apache Solr Tutorial
 
Sinatra
SinatraSinatra
Sinatra
 
Drupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, ScalingDrupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, Scaling
 
Serverless on OpenStack with Docker Swarm, Mistral, and StackStorm
Serverless on OpenStack with Docker Swarm, Mistral, and StackStormServerless on OpenStack with Docker Swarm, Mistral, and StackStorm
Serverless on OpenStack with Docker Swarm, Mistral, and StackStorm
 
Sinatra
SinatraSinatra
Sinatra
 
WebNano - Ideas for Web Frameworks
WebNano - Ideas for Web FrameworksWebNano - Ideas for Web Frameworks
WebNano - Ideas for Web Frameworks
 
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
Spark Saturday: Spark SQL & DataFrame Workshop with Apache Spark 2.3
 
Drupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from SunDrupal Efficiency using open source technologies from Sun
Drupal Efficiency using open source technologies from Sun
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 

Recently uploaded

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

Sinatra

  • 2. About Me Nick Zalabak Slides and code examples for this presentation: git@github.com:techwhizbang/sinatra_slideshow.git git@github.com:techwhizbang/sinatra_slideshow_code.git My Blog: http://techwhizbang.com Twitter: @techwhizbang
  • 3. Compelling Reasons Sinatra is a “microframework” built on Rack Easy, practical, go fast! Made with extensibility in mind Not crufty or bloated like larger web frameworks Small memory footprint as compared to other frameworks On par performance-wise to other frameworks Works well with many web servers Works great with JRuby
  • 4. Sinatra 101 Sinatra is more DSL atop Rack than your typical “framework” DSL Configuration DSL Routing Works with many popular template/view libraries Has before and after filters similar to Rails Handles all typical response codes and mime types nicely Easy testing with popular test frameworks/libraries
  • 5. Project Layout There is no set project layout per se Use best practices and judgment Nobody likes a “fiddly little snowflake app”
  • 6. Configuration Sinatra is configurable “Out of box” settings are usually OK enable/disable are often overlooked set RACK_ENV=dev|test|prod
  • 7. Sessions Surprise! Sessions are off by default Default cookie based sessions via Rack Memory? Rack::Session::Pool Distributed? Rack::Session::Memcache
  • 8. Cookies response.set_cookie(“viewed_products”, “1,2,3”) reponse.set_cookie(“viewed_products”, [1,2,3]) reponse.delete_cookie(“viewed_products”) request.cookies[“viewed_products”]
  • 9. Serving css, js, etc By default Sinatra serves from ‘public’ public, root, views are configurable use Rack::Static when not standalone
  • 10. Routing It’s as simple as GET, POST, PUT, DELETE
  • 11. Templating Erb, HAML, Sass, Erubis, Builder support erb :template, sass :template, etc Named templating Inline templating
  • 12. Filters Rails inspired before/after filters similar
  • 13. Helpers Can be used in templates and controllers
  • 14. Database Connectivity “Roll your own” strategy Connections Migrations Extensions sinatra-activerecord sinatra-mongo sinatra-sequel
  • 15. Load your Rake tasks Load your own Rake tasks
  • 16. Caching Gems & Extensions sinatra-cache rack-cache
  • 17. Logging Use a plain Ruby logger sinatra-logger extension
  • 18. Testing Sinatra gem rack-test include Rack::Test::Methods last_response variable provides access to response body, headers, status, etc last_request variable provides access to host, cookies, referrer, params, post?, get?, delete?, put?, path, etc
  • 19. Ways to ‘start’ Sinatra Basic standalone mode ruby basic_startup.rb Use a Rackup file - config.ru thin -s 2 -C config.yml-R config.ru start
  • 20. If Sinatra were a gateway drug… It would lead to Rack
  • 21. Handy Rack Middlewarez rack-contrib rack-throttle rack-bug rack-flash warden See for yourself and search “rack” on GitHub
  • 22. Sinatra + Bundler Get the bundler gem bundle init Edit your Gemfile Add Bundler.setup
  • 23. Code Counter Sinatra lines of code for tests? 3685 Sinatra actual lines of library code? 2248 Rails 2.3.x approx 156000
  • 24. Load testing Sinatra How does it perform under load? Sinatra is thread safe (try w/JRuby)
  • 25. Sinatra + Jruby + Warbler jruby –S gem install warbler mkdirconfig warble config Check config/warble.rb
  • 26. Sinatra on Heroku Version your app with Git(hub) (git init) Use Bundler or .gems file to manage Gems sudo gem install heroku heroku create git push heroku master See your gems installed in the terminal It really is that easy! http://stormy-earth-60.heroku.com/products
  • 27. Sinatra in Action GitHubresque gem Github Watchtower Heroku: processing background jobs Cafepress: internal RESTful services
  • 28. Q&A

Editor's Notes

  1. These are just some compelling reasons to give Sinatra a strong consideration the next time you start a new project
  2. To further qualify that Sinatra is more DSL than framework take a close look at the implementation details to the some of the more important things likelogging, sessions, method override. These are all implemented by Rack, not Sinatra.
  3. I’ve seen some configure their Sinatra app like a gem, some like a Rails stack, and some are of the simple containing 1 or 2 files
  4. All configuration settings are documented here http://www.sinatrarb.com/configuration.htmlWeb server configurations will be discussed later in the deck
  5. Refer to the cookie_sessions_controller.rb,memcache_sessions_controller.rb, memory_sessions_controller.rbIf you need to customize your session cookie timeout, domain, or secret keyuse Rack::Session::Cookie, :key => 'rack.session', :domain => 'foo.com', :path => '/', :expire_after => 2592000, # In seconds :secret => 'change_me’You can pass in the standard Memcache options, look at the memcache-client gem for more about the config settingsBoth the memory and memcache session stores still use the cookie to store the session keyDON’T use enable :session or :session, true with alternate session storesDemonstrate the differences of the memory vsmemcache by stopping and restarting the server
  6. Refer to products_controller.rbview_products methodCookie implementation is again Rack::Request and Rack::Response based, not SinatraCan serialize Array objects, but you must parse them out yourself when delimited by &’sCan modify the domain, path, and expiration of the cookie Strings will need to be manually escapedLook in the products controller show method
  7. Refer to the search_controller.rbIfSinatra isn’t in standalone mode and your using another web server be sure to specify Rack::Static
  8. URI definition should look similar to RailsMentionsplatting get '/say/*/to/*' do # matches /say/hello/to/world params["splat"] # => ["hello", "world"] end
  9. Refer to the standalone_controller.rbMentionthe gotcha with the XML builder templates, the xml variable in the template is automatically initialized for you
  10. Refer to the search_controller.rb
  11. Refer to the products_controller.rb
  12. Go back to the db_migrate task to show how easy db:migrate can be done yourself
  13. sinatra-cache extension does file based page and fragment caching, this is completely file basedsinatra-cache is implemented in the search controller and views within the examplesFor rack-cache refer to products_controller.rbrack-cache is HTTP based caching based on Etag and Last modified headers that supports memory, disk, and memcache storesEntity stores are used to cache response bodies across requests. Meta stores are used for request/response pair keyed by the request's URLrack-cache is a lightweight alternative to squid or other high throughput proxy serversrack-cache is implemented in the products controller within the examples
  14. Bundler is great since it makes your application completely portable without worrying about gems on the deploy serverIt is also keeps you honest
  15. find . -name *.rb -print0 | xargs -0 wc -l
  16. Start up Jmeter and top to monitor
  17. Jruby-rack Jar allows us to interface to all rack based apps via servlet filter in the web.xmlHave to change config/warble.rb to accommodate your Sinatra app layoutDeployable to your favorite JEE/Servlet container Tomcat, Jboss, Glassfish…http://github.com/nicksieger/jruby-rack/tree/master/exampleshttp://github.com/nicksieger/jruby-rack.git
  18. Resque is background job processor with Sinatra UI for monitoring queues, jobs, workersWatchtower is a combo of Mongo DB, Mustache templating, and Sinatra UI