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

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 

Último (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 

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