SlideShare uma empresa Scribd logo
1 de 28
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

Mais conteúdo relacionado

Semelhante a Sinatra

Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Servicevvatikiotis
 
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 rubyDeepak Chandella
 
Mahout Introduction BarCampDC
Mahout Introduction BarCampDCMahout Introduction BarCampDC
Mahout Introduction BarCampDCDrew Farris
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfssusercd195b
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael 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 米嘉 gobuildwebLeo 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 ActivatorKevin Webber
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike 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 & CucumberUdaya Kiran
 
Dev8d Apache Solr Tutorial
Dev8d Apache Solr TutorialDev8d Apache Solr Tutorial
Dev8d Apache Solr TutorialSourcesense
 
Drupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, ScalingDrupal Efficiency - Coding, Deployment, Scaling
Drupal Efficiency - Coding, Deployment, Scalingsmattoon
 
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 StackStormDmitri Zimine
 
WebNano - Ideas for Web Frameworks
WebNano - Ideas for Web FrameworksWebNano - Ideas for Web Frameworks
WebNano - Ideas for Web Frameworksguestf89f9cb
 
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.3Databricks
 
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 Sunsmattoon
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 

Semelhante a 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
 

Último

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

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

Notas do Editor

  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