Something something rack
Upcoming SlideShare
Loading in...5
×
 

Something something rack

on

  • 2,409 views

My introduction talk to Rack at ArrrrCamp (http://arrrrcamp.be)

My introduction talk to Rack at ArrrrCamp (http://arrrrcamp.be)

Statistics

Views

Total Views
2,409
Views on SlideShare
2,375
Embed Views
34

Actions

Likes
2
Downloads
14
Comments
0

6 Embeds 34

http://tech.jorendegroof.be 19
http://www.slideshare.net 7
http://theoldreader.com 5
http://dejoren.be 1
http://feeds.feedburner.com 1
http://tussenhaakjes.be 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • wrapping HTTP requests and responses in the simplest way possible <br />
  • <br /> <br />
  • rack includes several handlers for the first web servers, the other distributions have included rack handlers on their own <br />
  • this means, you can run any of these frameworks on any of the previous web servers! without any changes <br /> <br /> Camping support is included in rack <br />
  • accepts basic ruby object <br /> like a lambda <br />
  • accepts basic ruby object <br /> like a lambda <br />
  • basic ruby object respond to call <br /> like a lambda <br />
  • take 1 argument <br /> the environment <br />
  • accepts basic ruby object <br /> like a lambda <br />
  • accepts basic ruby object <br /> like a lambda <br />
  • hash <br /> key value pairs for header <br />
  • body <br /> must respond to each <br /> now just a string in an Array <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • don&#x2019;t need to use lambda&#x2019;s <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • http style header params <br />
  • like http accept <br />
  • rack namespaced protected keys in the environment <br /> <br />
  • your own environment namespace <br />
  • wrap it in a request object <br />
  • <br />
  • normal <br /> builder <br /> toto <br />
  • everytinh in front of our app <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • call down the next thing down stream <br /> this is the power of the middleware <br /> returning the result <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Something something rack Something something rack Presentation Transcript

  • SOMETHING SOMETHING RACK
  • OH, HI! • Joren • Openminds • @joren • tech.jorendegroof.be
  • OVERVIEW • Rack what? • Why Rack? • How do you use it? • Middleware
  • RACK WHAT?
  • RACK WHAT? Rack is a specification (and implementation) of a minimal abstract Ruby API that models HTTP
  • WHY RACK? • Stop writing handlers for every webserver • Keep the request and response simple
  • WHY RACK? Supported web servers
  • WHY RACK? Supported web frameworks
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT?
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • HOW DO YOU USE IT? How to call it? run lambda { |env| [ 200, { ‘Content-Type’ => ‘text/plain’, ‘Content-Lenght’ => ‘5’, }, [‘Hello’] ] }
  • config.ru
  • $ rackup config.ru
  • $ curl http://localhost:9292
  • Hello
  • HOW DO YOU USE IT? class HelloWorld def call(env) [200, {"Content-Type" => "text/plain"}, ["Hello World!"]] end end
  • env
  • REQUEST_METHOD
  • env[‘REQUEST_METHOD’]
  • GET PUT POST DELETE HEAD OPTIONS TRACE
  • PATH_INFO
  • /items/123
  • HTTP_*
  • HTTP_ACCEPT
  • rack.*
  • yournamespace.*
  • request = Rack::Request.new(env)
  • request.post?
  • HOW DO YOU USE IT? Example
  • MIDDLEWARE Middleware App HTTP
  • use Middleware A use Middleware B use Middleware C run app
  • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
  • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
  • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
  • class GoSlower def initialize(app) @app = app end def call(env) sleep(1) @app.call(env) end end
  • IN YOUR RAILS APP #environment.rb config.middleware.use “Rack::GoSlower” config.middleware.use “Rack::Cache”, :verbose => true, :metastrore => ‘file:/path/to/dir’, :entitystore => 'memcached://localhost:11211/body'
  • EXAMPLES
  • RACK::HONEYPOT http://github.com/sunlightlabs/rack-honeypot
  • RACK::CACHE http://github.com/rtomayko/rack-cache
  • WARDEN + DEVISE http://github.com/hassox/warden http://github.com/plataformatec/devise
  • RACK::DEBUG http://github.com/ddollar/rack-debug
  • RACK::GEOIP http://github.com/b/rack-geoip
  • RACK::GOOGLE-ANALYTICS http://github.com/leehambley/rack-google-analytics
  • RACK::REWRITE http://github.com/jtrupiano/rack-rewrite
  • RACK::MOBILE-DETECT http://github.com/talison/rack-mobile-detect
  • RACK::CONTRIB http://github.com/rack/rack-contrib
  • QUESTIONS?