- Number 2 most downloaded gem on rubygems.org
- A spec for code that responds to HTTP:
- Object that responds to
call
- Takes one argument (
env
) - Returns
[status, headers, body]
wherebody
responds toeach
- Object that responds to
- Universal adapter
- Original design
- Only useful for framework/webserver designers
- Good model for HTTP requests
- Middleware
- Class or proc based.
env
is a big hash of stuff from the request. See app the outputs itsenv
and list of keys in such an env
- Sits between the user and the app
- Can intercept requests/responses and modify them
- Can be chained together
Example middleware (logs time):
- Shortcut to all the nesting
use
for Middleware (classes)run
for apps (instance)- run via the command-line with
rackup
Example middleware (logs time):
- Rails apps are rack apps (see
config.ru
) - Rails has middleware (see
rake middleware
) - Cookies, sessions, and params are handled by middleware
- Routes can point to any Rack app (or stack)
Rack::Attack
(rate limiting)Rack::Honeypot
(spam trap)