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, like 200 or 404.
  • headers β€” a hash of header names to values. Rack 3 requires lowercase header names: "content-type", not "Content-Type".
  • body β€” anything that responds to each and 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).