Day23
I’m starting to get an overall picture of how Ruby becomes a web application.
By default, Ruby is just a programming language you use to write scripts and run them in the terminal. It doesn’t know anything about browsers, URLs, or HTTP.
So how does Ruby end up working on the web?
It needs two things.
First, a web server, for example, Puma. The web server listens for HTTP requests from a browser and sends HTTP responses back. HTTP is the language of the web, and without a web server, Ruby has no way to “hear” the browser.
Second, it needs a standard interface between the web server and Ruby code. That’s where Rack comes in.
Rack defines a simple agreement: the web server hands a request to Ruby as a hash, and Ruby returns a response in a fixed structure. Rack doesn’t try to be friendly or convenient. It is intentionally low-level so everything can be built on top of it.
With just Puma and Rack, it is already possible to build a web application. But doing everything at this level is cumbersome.
That’s why frameworks exist.
Frameworks like Sinatra, Ruby on Rails, Padrino, Hanami, and others sit on top of Rack. They don’t replace it. They simply make web development easier by providing structure, routing, and higher-level abstractions.