MΓ³dulo 05 Β· HTTP & Rack β LecciΓ³n 2 de 4 Β· ~9 min
The Rack Contract
One contract, every framework
Rails. Sinatra. Every Ruby web framework you'll ever touch. Underneath all of them is the same tiny agreement, called Rack: a web app is ANY Ruby object that responds to call(env) and returns a 3-element array β [status, headers, body].
envβ a hash describing the incoming request (method, path, headers β you'll read from it directly in the next lesson).statusβ an integer, like200or404.headersβ a hash of header names to values. Rack 3 requires lowercase header names:"content-type", not"Content-Type".bodyβ anything that responds toeachand yields strings. An array of one string is the simplest possible body.
That's it. No inheritance, no base class to extend β just an object with a call method shaped the right way. Rails itself is, underneath everything, one very large object that answers call(env).