Your SlideShare is downloading. ×
0
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Rack
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rack

1,760

Published on

A short presentation on Rack middleware I gave at the 10/21/2010 NovaRUG.

A short presentation on Rack middleware I gave at the 10/21/2010 NovaRUG.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,760
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Rack Scott Leberknight
  • 2. HTTP make request, get response
  • 3. Request a hash containing the environment (headers, params, input stream)
  • 4. Response status, headers, body
  • 5. Simplest Rack App..
  • 6. class Hello status def call(env) headers [ 200, { "Content-Type" => "text/plain" }, [ "Hello!", "Having fun yet?" ] ] end end body
  • 7. Middleware Order Matters !
  • 8. middlewares call() each other... and act like chain of response filters... ...so the order you use them matters!
  • 9. init with app class Reverse def initialize(app) first, Call the app @app = app end def call(env) status, headers, body = @app.call(env) [status, headers, body.map { |b| b.reverse }] end end then, do your stuff
  • 10. use Rack::ContentLength use RackExamples::Paragraphizer use RackExamples::Upcase use use RackExamples::Downcase RackExamples::Reverse Is output upper or app = lambda { |env| [ lower case? 200, { 'Content-Type' => 'text/html' }, ["Dammit, I'm mad!", "Was it a rat I saw?", "Madam, I'm Adam"] ] } run app 11
  • 11. use Rack::ContentLength use RackExamples::Paragraphizer use RackExamples::Downcase use RackExamples::Upcase use RackExamples::Reverse How about now? app = lambda { |env| [ 200, { 'Content-Type' => 'text/html' }, ["Dammit, I'm mad!", "Was it a rat I saw?", "Madam, I'm Adam"] ] } run app 12
  • 12. "Off t he Shelf"
  • 13. Rack::ShowExceptions Rack::MailExceptions Rack::CommonLogger Rack::ContentLength Rack::JSON ActionController::StringCoercion Rack::ETag Rack::Deflater ...and lots more
  • 14. Baked into Ra ils
  • 15. $ rake middleware (in /Users/sleberkn/Projects/my-niclabs) use Rack::Lock use ActionController::Failsafe use ActionController::Session::CookieStore, #<Proc:0x00000001017acf18@(eval):8> use ActionController::ParamsParser use Rack::MethodOverride use Rack::Head use ActionController::StringCoercion use Rack::Deflater use Sass::Plugin::Rack use ActiveRecord::ConnectionAdapters::ConnectionManagement use ActiveRecord::QueryCache run ActionController::Dispatcher.new
  • 16. Summary
  • 17. References
  • 18. http://lmgtfy.com/?q=ruby+rack http://www.letmebingthatforyou.com/?q=ruby+rack
  • 19. Image credits Shelf thedesignblog.org/entry/odersoding-storage-system-doubles-as-a-room-divider/ Cool newgeography.com Baking haileythebaketress.blogspot.com Json nearinfinity.com
  • 20. scott.leberknight@nearinfinity.com www.nearinfinity.com/blogs/ twitter: sleberknight

×