SlideShare a Scribd company logo
1 of 57
Download to read offline
Rails Metal,
Rack, and Sinatra

Adam Wiggins
Railsconf 2009
Show of hands, how
many of you...
metal
Show of hands, how
many of you...
“The gateway drug”
“The gateway drug”*



* it’s a myth, but makes good analogy
Rails Metal is a
gateway
Rails Metal is a
gateway to the
world of Rack
What can you do with
Metal?
Replace selected
URLs for a speed
boost
Example: auction site
Example: auction site
Example: auction site



            on
Majority of traffic goes to:


GET /auctions/id.xml
app/controller/auctions_controller.rb
app/controller/auctions_controller.rb

class AuctionsController < ApplicationController
  def show
    @auction = Auction.find(params[:id])

    respond_to do |format|
      format.html
      format.xml { render :xml => @auction }
    end
  end
end
app/metal/auctions_api.rb
app/metal/auctions_api.rb

class AuctionsApi
  def self.call(env)
    # implementation goes here




  end
end
app/metal/auctions_api.rb

class AuctionsApi
  def self.call(env)
    url_pattern = %r{/auctions/(d+).xml}

    if m = env['PATH_INFO'].match(url_pattern)
      # render the auction api



    else
      # pass (do nothing)
    end
  end
end
app/metal/auctions_api.rb

class AuctionsApi
  def self.call(env)
    url_pattern = %r{/auctions/(d+).xml}

    if m = env['PATH_INFO'].match(url_pattern)
      auction = Auction.find(m[1])
      [ 200, {quot;Content-Typequot; => quot;text/xmlquot;},
        auction.to_xml ]
    else
      [ 404, {}, '' ]
    end
  end
end
[
    200,
    {quot;Content-Typequot;=>quot;text/plainquot;},
    quot;Hello, Rack!quot;
]
[
    200,
    {quot;Content-Typequot;=>quot;text/plainquot;},
    quot;Hello, Rack!quot;
]
http://www.slideshare.net/adamwiggins/
ruby-isnt-just-about-rails-presentation
An explosion of Ruby
projects in the past 2
years
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController
                    RSpec
 Merb
                    Shoulda
 Sinatra

ORM                     Templating
ActiveRecord            Erb
DataMapper              Haml
Sequel                  Erubis

                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
                     Thin
   RestClient
                     Ebb
   HTTParty
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController



ORM                     Templating
ActiveRecord            Erb




                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController



ORM                     Templating
ActiveRecord            Erb




                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController
                    RSpec
 Merb
                    Shoulda
 Sinatra

ORM                     Templating
ActiveRecord            Erb
DataMapper              Haml
Sequel                  Erubis

                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
                     Thin
   RestClient
                     Ebb
   HTTParty
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController
                    RSpec
 Merb
                    Shoulda
 Sinatra

ORM                     Templating
ActiveRecord            Erb
DataMapper              Haml
Sequel                  Erubis

                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
                     Thin
   RestClient
                     Ebb
   HTTParty
Tests/Specs
 Web Layer
                    Test::Unit
 ActionController
                    RSpec
 Merb
                    Shoulda
 Sinatra

ORM                     Templating
ActiveRecord            Erb
DataMapper              Haml
Sequel                  Erubis

                     Web Server
   HTTP Client
                     Mongrel
   ActiveResource
                     Thin
   RestClient
                     Ebb
   HTTParty
The world of Rack is
now within reach from
Rails
Sinatra
The classy
microframework for Ruby



http://sinatrarb.com
require 'rubygems'
require 'sinatra'

get '/hello' do
  quot;Hello, whirledquot;
end
$ ruby hello.rb
== Sinatra/0.9.1.1 has taken the stage
>> Thin web server (v1.0.0)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567
$ ruby hello.rb
== Sinatra/0.9.1.1 has taken the stage
>> Thin web server (v1.0.0)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:4567

$ curl http://localhost:4567/hello
Hello, whirled
A minimalist paradise
require 'rubygems'
require 'sinatra'
require 'lib/article'

post '/articles' do
  article = Article.create! params
  redirect quot;/articles/#{article.id}quot;
end

get '/articles/:id' do
  @article = Article.find(params[:id])
  erb :article
end
Sinatra in your Rails
app?
Replace selected
URLs for a speed
boost
Replace selected
URLs for a speed
boost
Replace selected
URLs with Sinatra
app/metal/articles.rb
app/metal/articles.rb
require 'sinatra/base'

class Articles < Sinatra::Base
  post '/articles' do
    article = Article.create! params
    redirect quot;/articles/#{article.id}quot;
  end

  get '/articles/:id' do
    @article = Article.find(params[:id])
    erb :article
  end
end
Back to the auction
example
Back to the auction
example
ActionController
class AuctionsController < ApplicationController
  def show
    @auction = Auction.find(params[:id])

    respond_to do |format|
      format.html
      format.xml { render :xml => @auction }
    end
  end
end
Pure Rack
class AuctionsApi
  def self.call(env)
    url_pattern = /^/auctions/(d+).xml$/

    if m = env['PATH_INFO'].match(url_pattern)
      auction = Auction.find(m[1])
      [ 200, {quot;Content-Typequot; => quot;text/xmlquot;},
        auction.to_xml ]
    else
      [ 404, {}, '' ]
    end
  end
end
Sinatra
get '/auctions/:id.xml'
 Auction.find(params[:id]).to_xml
end
Sinatra
get '/auctions/:id.xml'
 Auction.find(params[:id]).to_xml
end




Now that’s what I call

         minimalist.
The End.
http://railscasts.com/episodes/150-rails-metal
http://rack.rubyforge.org
http://sinatrarb.com

http://adam.blog.heroku.com

Adam Wiggins
Railsconf 2009

More Related Content

What's hot

When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
benbrowning
 
Mongrel Handlers
Mongrel HandlersMongrel Handlers
Mongrel Handlers
nextlib
 

What's hot (19)

Foreman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsForeman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple components
 
Ninad cucumber rails
Ninad cucumber railsNinad cucumber rails
Ninad cucumber rails
 
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
JavaOne: A tour of (advanced) akka features in 60 minutes [con1706]
 
A tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutesA tour of (advanced) Akka features in 40 minutes
A tour of (advanced) Akka features in 40 minutes
 
When Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the EnterpriseWhen Two Worlds Collide: Java and Ruby in the Enterprise
When Two Worlds Collide: Java and Ruby in the Enterprise
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)Wire once, rewire twice! (Haskell exchange-2018)
Wire once, rewire twice! (Haskell exchange-2018)
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
 
Mongrel Handlers
Mongrel HandlersMongrel Handlers
Mongrel Handlers
 
Devignition 2011
Devignition 2011Devignition 2011
Devignition 2011
 
.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011.NET Architects Day - DNAD 2011
.NET Architects Day - DNAD 2011
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011TorqueBox at DC:JBUG - November 2011
TorqueBox at DC:JBUG - November 2011
 
Crash course to the Apache Camel
Crash course to the Apache CamelCrash course to the Apache Camel
Crash course to the Apache Camel
 
Rack is Spectacular
Rack is SpectacularRack is Spectacular
Rack is Spectacular
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 

Viewers also liked

The 7 P's of Physician Brand Marketing
The 7 P's of Physician Brand MarketingThe 7 P's of Physician Brand Marketing
The 7 P's of Physician Brand Marketing
Matthew Scott
 

Viewers also liked (20)

Free workshop: Carbon Footprint 101
Free workshop: Carbon Footprint 101Free workshop: Carbon Footprint 101
Free workshop: Carbon Footprint 101
 
Voting powerpoint
Voting powerpointVoting powerpoint
Voting powerpoint
 
YOU ARE A BRAND: Social media and job market
YOU ARE A BRAND: Social media and job marketYOU ARE A BRAND: Social media and job market
YOU ARE A BRAND: Social media and job market
 
The Brand Gap
The Brand GapThe Brand Gap
The Brand Gap
 
Twitter At Interaction09
Twitter At Interaction09Twitter At Interaction09
Twitter At Interaction09
 
Sin título 1
Sin título 1Sin título 1
Sin título 1
 
The Integral Designer: Developing You
The Integral Designer: Developing YouThe Integral Designer: Developing You
The Integral Designer: Developing You
 
Finding Your Story: Branding & Positioning in the Hosting Industry
Finding Your Story: Branding & Positioning in the Hosting IndustryFinding Your Story: Branding & Positioning in the Hosting Industry
Finding Your Story: Branding & Positioning in the Hosting Industry
 
DIY UX - Higher Ed
DIY UX - Higher EdDIY UX - Higher Ed
DIY UX - Higher Ed
 
The 7 P's of Physician Brand Marketing
The 7 P's of Physician Brand MarketingThe 7 P's of Physician Brand Marketing
The 7 P's of Physician Brand Marketing
 
Public opinion
Public opinionPublic opinion
Public opinion
 
What is Crowdsourcing
What is CrowdsourcingWhat is Crowdsourcing
What is Crowdsourcing
 
DIY UX: Give Your Users an Upgrade (Without Calling In a Pro)
DIY UX: Give Your Users an Upgrade (Without Calling In a Pro)DIY UX: Give Your Users an Upgrade (Without Calling In a Pro)
DIY UX: Give Your Users an Upgrade (Without Calling In a Pro)
 
Evangelizing Yourself
Evangelizing YourselfEvangelizing Yourself
Evangelizing Yourself
 
Data Driven Design Research Personas
Data Driven Design Research PersonasData Driven Design Research Personas
Data Driven Design Research Personas
 
Transcending Our Tribe
Transcending Our TribeTranscending Our Tribe
Transcending Our Tribe
 
Do You Speak Jackal or Giraffe? Designing Sustainable Relationships
Do You Speak Jackal or Giraffe? Designing Sustainable RelationshipsDo You Speak Jackal or Giraffe? Designing Sustainable Relationships
Do You Speak Jackal or Giraffe? Designing Sustainable Relationships
 
What's Your Problem? Putting Purpose Back into Your Projects
What's Your Problem? Putting Purpose Back into Your ProjectsWhat's Your Problem? Putting Purpose Back into Your Projects
What's Your Problem? Putting Purpose Back into Your Projects
 
Startup Marketing
Startup MarketingStartup Marketing
Startup Marketing
 
The Brand Gap
The Brand GapThe Brand Gap
The Brand Gap
 

Similar to Rails Metal, Rack, and Sinatra

20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
Takeshi AKIMA
 
2010-04-13 Reactor Pattern & Event Driven Programming 2
2010-04-13 Reactor Pattern & Event Driven Programming 22010-04-13 Reactor Pattern & Event Driven Programming 2
2010-04-13 Reactor Pattern & Event Driven Programming 2
Lin Jen-Shin
 

Similar to Rails Metal, Rack, and Sinatra (20)

Ruby and Rails for womens
Ruby and Rails for womensRuby and Rails for womens
Ruby and Rails for womens
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails09 - Fábio Akita - Além do rails
09 - Fábio Akita - Além do rails
 
Merb tutorial
Merb tutorialMerb tutorial
Merb tutorial
 
Deployment de Rails
Deployment de RailsDeployment de Rails
Deployment de Rails
 
RoR 101: Session 1
RoR 101: Session 1RoR 101: Session 1
RoR 101: Session 1
 
Lets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagiLets build-ruby-app-server: Vineet tyagi
Lets build-ruby-app-server: Vineet tyagi
 
Rails 2.0 Presentation
Rails 2.0 PresentationRails 2.0 Presentation
Rails 2.0 Presentation
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Php assíncrono com_react_php
Php assíncrono com_react_phpPhp assíncrono com_react_php
Php assíncrono com_react_php
 
Angular for rubyists
Angular for rubyistsAngular for rubyists
Angular for rubyists
 
Sinatra Introduction
Sinatra IntroductionSinatra Introduction
Sinatra Introduction
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
 
2010-04-13 Reactor Pattern & Event Driven Programming 2
2010-04-13 Reactor Pattern & Event Driven Programming 22010-04-13 Reactor Pattern & Event Driven Programming 2
2010-04-13 Reactor Pattern & Event Driven Programming 2
 
Where is my scalable API?
Where is my scalable API?Where is my scalable API?
Where is my scalable API?
 
Ruby Conf Preso
Ruby Conf PresoRuby Conf Preso
Ruby Conf Preso
 

More from Adam Wiggins (6)

Waza keynote: Idea to Delivery
Waza keynote: Idea to DeliveryWaza keynote: Idea to Delivery
Waza keynote: Idea to Delivery
 
The Epic Pivot: Heroku's Story
The Epic Pivot: Heroku's StoryThe Epic Pivot: Heroku's Story
The Epic Pivot: Heroku's Story
 
Cloud Services
Cloud ServicesCloud Services
Cloud Services
 
Next-Generation Ruby Deployment with Heroku
Next-Generation Ruby Deployment with HerokuNext-Generation Ruby Deployment with Heroku
Next-Generation Ruby Deployment with Heroku
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP Tricks
 
rush, the Ruby shell and Unix integration library
rush, the Ruby shell and Unix integration libraryrush, the Ruby shell and Unix integration library
rush, the Ruby shell and Unix integration library
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Rails Metal, Rack, and Sinatra