Rack Rocks!
Chan Myae San Hlaing
Facebook: Chan Myae San Hlaing
Twitter: @jjrofriloc
Github: @dreamingblackcat
Freelance Developer at toptal.com
Slide 2
Slide 2 text
The Web
Slide 3
Slide 3 text
Web Applications
Slide 4
Slide 4 text
Ruby Web Servers
Ruby Web Frameworks
Slide 5
Slide 5 text
Ruby Web Servers
Ruby Web Frameworks
Slide 6
Slide 6 text
Rack
●
Inspired from Python WSGI spec
●
Both Spec and Implementation
●
Middleware Pattern
Slide 7
Slide 7 text
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 )
Slide 8
Slide 8 text
Hello World
Slide 9
Slide 9 text
What's in the env?
Slide 10
Slide 10 text
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
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
Slide 15
Slide 15 text
Endpoints
Slide 16
Slide 16 text
Rack Builder
●
A DSL for declaring rack middlewares
●
Comes built-in with rack gem
Slide 17
Slide 17 text
Rails is built on top of Rack
http://guides.rubyonrails.org/rails_on_rack.html
Slide 18
Slide 18 text
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
Slide 19
Slide 19 text
●
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
Slide 20
Slide 20 text
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.
Slide 21
Slide 21 text
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