SlideShare a Scribd company logo
WHAT THE RACK ?!
O QUE É ?
app.call(env)
, …
REQUEST_METHOD: HEAD
REQUEST_PATH: /
PATH_INFO: /
REQUEST_URI: /
HTTP_VERSION: HTTP/1.1
HTTP_USER_AGENT: curl/7.21.4 (universal-apple-
darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
HTTP_HOST: localhost:3000
HTTP_ACCEPT: ! '*/*'
GATEWAY_INTERFACE: CGI/1.2
SERVER_PORT: '3000’
… -
app.call(env)
=> *200, ,‘Content-Type’=> ‘text/plain’ -, ‘Hello World !’+
Require ‘thin’
Rack::Handler::Thin.run(app, port: 4000)
WRITE ONCE, SERVE
EVERYWHERE !
class HelloWorld
def initialize(name)
@name = name
end
def call(env)
*200, , ‘Content-Type’ => ‘text/plain’ -
end
end
require ‘rubygems
require ‘rack’
Rack::Handler::Mongrel.run(HelloWorld.new(“Dan”), port: 4000)
MIDDLEWARE
class ResponseTimer
def initialize(app, message = "Response Time")
@app = app
@message = message
end
def call(env)
start = Time.now
status, headers, response = @app.call(env)
stop = Time.now
if headers["Content-Type"].include? "text/html"
[status, headers, "<!-- #{@message}: #{stop - start} -->n" +
response.body]
else
[status, headers, response]
end
end
end
Rails::Initializer.run do |config|
config.middleware.use "ResponseTimer", "Load Time"
end

More Related Content

What's hot

Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
Arnout Kazemier
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
Workhorse Computing
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
Aaron Stannard
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.io
Mindfire Solutions
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
som_nangia
 
Composer: Dependency Manager for PHP
Composer: Dependency Manager for PHPComposer: Dependency Manager for PHP
Composer: Dependency Manager for PHP
Hampton Roads PHP User Grop
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
hendrikvb
 
Socket.io
Socket.ioSocket.io
Socket.io
Antonio Terreno
 
CocoaPods
CocoaPodsCocoaPods
CocoaPods
Denis Lebedev
 
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
emptysquare
 
node.js workshop- node.js middleware
node.js workshop- node.js middlewarenode.js workshop- node.js middleware
node.js workshop- node.js middleware
Qiong Wu
 
On connection lost
On connection lostOn connection lost
On connection lost
Lukasz Plotnicki
 
Phl mongo-philly-tornado-2011
Phl mongo-philly-tornado-2011Phl mongo-philly-tornado-2011
Phl mongo-philly-tornado-2011
hangxin1940
 
node.js workshop- node.js basics
node.js workshop- node.js basicsnode.js workshop- node.js basics
node.js workshop- node.js basics
Qiong Wu
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Dead
noamt
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
noamt
 
Express js
Express jsExpress js
Express js
Manav Prasad
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
Vic Metcalfe
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
Gabriele Lana
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
Masahiro Nagano
 

What's hot (20)

Going real time with Socket.io
Going real time with Socket.ioGoing real time with Socket.io
Going real time with Socket.io
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 
Intro to Node
Intro to NodeIntro to Node
Intro to Node
 
Real Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.ioReal Time Communication using Node.js and Socket.io
Real Time Communication using Node.js and Socket.io
 
Psgi Plack Sfpm
Psgi Plack SfpmPsgi Plack Sfpm
Psgi Plack Sfpm
 
Composer: Dependency Manager for PHP
Composer: Dependency Manager for PHPComposer: Dependency Manager for PHP
Composer: Dependency Manager for PHP
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Socket.io
Socket.ioSocket.io
Socket.io
 
CocoaPods
CocoaPodsCocoaPods
CocoaPods
 
What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?What Is Async, How Does It Work, And When Should I Use It?
What Is Async, How Does It Work, And When Should I Use It?
 
node.js workshop- node.js middleware
node.js workshop- node.js middlewarenode.js workshop- node.js middleware
node.js workshop- node.js middleware
 
On connection lost
On connection lostOn connection lost
On connection lost
 
Phl mongo-philly-tornado-2011
Phl mongo-philly-tornado-2011Phl mongo-philly-tornado-2011
Phl mongo-philly-tornado-2011
 
node.js workshop- node.js basics
node.js workshop- node.js basicsnode.js workshop- node.js basics
node.js workshop- node.js basics
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Dead
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Express js
Express jsExpress js
Express js
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7Operation Oriented Web Applications / Yokohama pm7
Operation Oriented Web Applications / Yokohama pm7
 

Viewers also liked

Green, lyneisha youteach ppt
Green, lyneisha youteach pptGreen, lyneisha youteach ppt
Green, lyneisha youteach ppt
Lyneisha Green
 
Final project
Final projectFinal project
Final project
trokon70
 
Bipolardisorderpwp
BipolardisorderpwpBipolardisorderpwp
Bipolardisorderpwp
jessiegestrin
 
Cv 2014 Federica Marini
Cv 2014 Federica MariniCv 2014 Federica Marini
Cv 2014 Federica Marini
Federica Marini
 
Fi nf068c73aef66f694f31a049aff3f4
Fi nf068c73aef66f694f31a049aff3f4Fi nf068c73aef66f694f31a049aff3f4
Fi nf068c73aef66f694f31a049aff3f4
Shawn D'souza
 
Aula 2 eg ecol ecos 2012
Aula 2 eg ecol ecos 2012Aula 2 eg ecol ecos 2012
Aula 2 eg ecol ecos 2012
lalivia
 
Epreuve de Physique Chimie au Bac S
Epreuve de Physique Chimie au Bac  SEpreuve de Physique Chimie au Bac  S
Epreuve de Physique Chimie au Bac Sscolaridee
 
Jack the Ripper
Jack the RipperJack the Ripper
Jack the Ripper
esterwassi
 
Nova friburgo
Nova friburgoNova friburgo
Nova friburgo
Regiwalt
 
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...Anna Shestakova
 
Barcelona city hall
Barcelona city hallBarcelona city hall
Barcelona city hall
raquel_ht
 
Matriks dan Determinan
Matriks dan DeterminanMatriks dan Determinan
Matriks dan DeterminanAndari Ursulla
 
Early lap assessment tools
Early lap assessment toolsEarly lap assessment tools
Early lap assessment tools
Marta Montoro
 
Precision Viticulture Ampelos 2013
Precision Viticulture Ampelos 2013Precision Viticulture Ampelos 2013
Precision Viticulture Ampelos 2013
Zacharias_Kandylakis
 
EuroBioForum 2013 - Day 2 | Marc Lapage
EuroBioForum 2013 - Day 2 | Marc LapageEuroBioForum 2013 - Day 2 | Marc Lapage
EuroBioForum 2013 - Day 2 | Marc Lapage
EuroBioForum
 
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistasEade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
JoyAlbanez
 

Viewers also liked (20)

Przykładowe moje prace
Przykładowe moje pracePrzykładowe moje prace
Przykładowe moje prace
 
Green, lyneisha youteach ppt
Green, lyneisha youteach pptGreen, lyneisha youteach ppt
Green, lyneisha youteach ppt
 
Final project
Final projectFinal project
Final project
 
Bipolardisorderpwp
BipolardisorderpwpBipolardisorderpwp
Bipolardisorderpwp
 
Cv 2014 Federica Marini
Cv 2014 Federica MariniCv 2014 Federica Marini
Cv 2014 Federica Marini
 
Fi nf068c73aef66f694f31a049aff3f4
Fi nf068c73aef66f694f31a049aff3f4Fi nf068c73aef66f694f31a049aff3f4
Fi nf068c73aef66f694f31a049aff3f4
 
Aula 2 eg ecol ecos 2012
Aula 2 eg ecol ecos 2012Aula 2 eg ecol ecos 2012
Aula 2 eg ecol ecos 2012
 
Epreuve de Physique Chimie au Bac S
Epreuve de Physique Chimie au Bac  SEpreuve de Physique Chimie au Bac  S
Epreuve de Physique Chimie au Bac S
 
Jack the Ripper
Jack the RipperJack the Ripper
Jack the Ripper
 
Virus
VirusVirus
Virus
 
Nieuwsbrief Fiscaal Maart 2012 Buro360 Accountants
Nieuwsbrief Fiscaal Maart 2012 Buro360 AccountantsNieuwsbrief Fiscaal Maart 2012 Buro360 Accountants
Nieuwsbrief Fiscaal Maart 2012 Buro360 Accountants
 
Nova friburgo
Nova friburgoNova friburgo
Nova friburgo
 
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...
Эксклюзивное интервью профессора Баева О.Р., Клинический протокол "Подготовка...
 
Barcelona city hall
Barcelona city hallBarcelona city hall
Barcelona city hall
 
Matriks dan Determinan
Matriks dan DeterminanMatriks dan Determinan
Matriks dan Determinan
 
Nieuwsbrief fiscaal mei 2012 buro360 accountants
Nieuwsbrief fiscaal mei 2012 buro360 accountantsNieuwsbrief fiscaal mei 2012 buro360 accountants
Nieuwsbrief fiscaal mei 2012 buro360 accountants
 
Early lap assessment tools
Early lap assessment toolsEarly lap assessment tools
Early lap assessment tools
 
Precision Viticulture Ampelos 2013
Precision Viticulture Ampelos 2013Precision Viticulture Ampelos 2013
Precision Viticulture Ampelos 2013
 
EuroBioForum 2013 - Day 2 | Marc Lapage
EuroBioForum 2013 - Day 2 | Marc LapageEuroBioForum 2013 - Day 2 | Marc Lapage
EuroBioForum 2013 - Day 2 | Marc Lapage
 
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistasEade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
Eade i-ii-6-a-escritura-dos-evangelhos-os-evangelistas
 

Similar to What the rack

Rack
RackRack
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
Gabriele Lana
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02
Sunny Gupta
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
DonSchado
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
danwrong
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
Tom Croucher
 
Nette framework (WebElement #28)
Nette framework (WebElement #28)Nette framework (WebElement #28)
Nette framework (WebElement #28)
Adam Štipák
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
Kent Ohashi
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
dantleech
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Kacper Gunia
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
Rubyc Slides
 
JavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronJavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to Electron
Brainhub
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
Masahiro Nagano
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
LittleBIGRuby
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
shaokun
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
Fabien Potencier
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
Alona Mekhovova
 

Similar to What the rack (20)

Rack
RackRack
Rack
 
Nodejs Explained with Examples
Nodejs Explained with ExamplesNodejs Explained with Examples
Nodejs Explained with Examples
 
Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02Nodejsexplained 101116115055-phpapp02
Nodejsexplained 101116115055-phpapp02
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
8 Minutes On Rack
8 Minutes On Rack8 Minutes On Rack
8 Minutes On Rack
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Nette framework (WebElement #28)
Nette framework (WebElement #28)Nette framework (WebElement #28)
Nette framework (WebElement #28)
 
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of PedestalInterceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
JavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronJavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to Electron
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Rails web api 开发
Rails web api 开发Rails web api 开发
Rails web api 开发
 
Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)Symfony 2 (PHP Quebec 2009)
Symfony 2 (PHP Quebec 2009)
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 

What the rack

Editor's Notes

  1. O Rack éuma interface entre o servidor e a suaaplicação ruby.Eleémais do que um framework, umabiblioteca, eleéumaconvenção ! O rails e o sinatrasãobaseadosnele, poiséeledámétodosmaisbaixonivelsemosquaisseriaimpossivelconstruirumaaplicação web.
  2. Se voce tem 1 objeto ruby querecebe 1 comoargumento e possui 1 métododefinidocomo CALL…
  3. Sendoqueseu ENV se pareceria com algodessetipo…
  4. E essemétodoretornauma array com 3 elementosquepossuiessacara… Status Code, HTTP Headers, Response Body
  5. Então voce podeconecta-lo a qualquerservidor web quesuporte o Rack… E tem a suaaplicação web
  6. Comoéumaconvencao largamente adotada, todososservidoresestão de ruby estãopreparadospara se comunicar com umaaplicação rack, tornando-a as aplicacoes rack “multi-servidoras”.
  7. Um Rack Middleware éumaaplicação rack (que no fundoéumaclasse ruby comooutraqualquer) quefuncionacomo um filtropara a suaaplicação Rails.
  8. Colocandoessaclassedentro de um arquivo lib no rails, temosuma middleware quenosdiz o tempo de resposta de cadaresquisicao.
  9. Colocandoessaclassedentro de um arquivo lib no rails, temosuma middleware quenosdiz o tempo de resposta de cadaresquisicao.