Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rack Rocks!

jjrofriloc
February 12, 2016

Rack Rocks!

Rack is the underlying technology behind Ruby web applications. This is an introduction to rack talk given at Myanmar Ruby Geeks Meetup #2 , Feb, 2016.

jjrofriloc

February 12, 2016
Tweet

More Decks by jjrofriloc

Other Decks in Programming

Transcript

  1. Rack Rocks! Chan Myae San Hlaing Facebook: Chan Myae San

    Hlaing Twitter: @jjrofriloc Github: @dreamingblackcat Freelance Developer at toptal.com
  2. Rack • Inspired from Python WSGI spec • Both Spec

    and Implementation • Middleware Pattern
  3. As Simple As Rack • Accept an env • Fiddle

    With It (or not) • Pass It to The Next Rack / Generate a Response • *Must Respond to #call method (yeah just like a Proc )
  4. What makes rack cool?! • Middlewares can be stacked •

    Acts as filters for HTTP req/res • Common API for accessing req/res • No more interface code for web servers • Middlewares can be mounted on each other • Interoperability between Rack-based Frameworks
  5. Endpoints • Responds a valid http response [status, headers, body

    ] • Handling errors • Application Endpoints • Another Stack of Rack Middlewares • Eg. Any Rails Controller Action/ Sinatra Route Block
  6. List of Rack Middlewares • Rack::Attack • Rack:GoogleAnalytics • Rack::Cache

    • Warden • Rack::Throttle • And many more.... https://github.com/rack/rack/wiki/List-of-Middleware
  7. • Minimalist Web Application Framework built on top of Rack

    • Encourage usage of Rack Middlewares • Highly Customizable • You will learn a lot about foundations of rails
  8. Make your own Rack Middleware • A simple class that

    accepts an app variable in initialize • Define a method #call • Use Rack::Request and Rack::Response classes to access req/res • Read other middlewares' source codes, *Seriously it's just a simple ruby class usually.
  9. Shameless Plug • A rack middleware to convert all incoming

    burmese inputs to Unicode • Used mmfont gem by @yelinaung and font detection code by @thuyamyonyunt • http://github.com/dreamingblackcat/mmunicode _rails
  10. References • http://confreaks.tv/videos/mwrc2010-rack-for-w eb-developers • http://confreaks.tv/videos/rubyweb2010-the-po wer-of-middleware-building-your-own-mini-web- framework-on-rack • http://confreaks.tv/videos/larubyconf2012-rack

    -middleware-as-a-general-purpose-abstraction • http://confreaks.tv/videos/scotlandruby2011-rea l-time-rack • http://www.slideshare.net/DonSchado/froscon-r ack