Skip to the workspace
Pebellslearn by building
Meet Rails  ›  Lesson

The Web, and Why Frameworks Exist

Why Web Frameworks? 12 minA web app answers HTTP requests with responses, and a framework like Rails handles the repeated plumbing so you only write the parts unique to your app.

ruby on rails / The Web, and Why Frameworks Exist

Explore each scene at your own pace.

01 · The rule

The rule

The Web, and Why Frameworks Exist

You type bookclub.example/books and a list of books appears. Between the key press and the page, a request crossed the internet, some code on a server decided what to send back, and your browser drew the result. Rails is a tool for writing that "some code" without reinventing every part of it.

The rule

A request asks, a response answers; the framework does the plumbing.

Every exchange on the web has two halves.

A request is the browser asking for something. Its core is a method and a path:

GET /books HTTP/1.1
Host: bookclub.example

GET means "give me this"; POST means "here is new data"; PATCH and DELETE change or remove things. The path names what you want.

A response is the server's answer: a status code and usually a body.

HTTP/1.1 200 OK
Content-Type: text/html

<h1>Books</h1> ...

200 means fine, 302 means "go over there instead", 404 means "no such page", and 500 means the server's own code crashed.

Now picture writing a server that handles this by hand. For every app you would write code to match paths to handlers, read form fields, talk to the database, escape HTML so users cannot inject scripts, remember who is logged in, and block forged form posts. Those jobs are the same in every app. A web framework is that shared plumbing, already written and tested. Rails adds strong conventions: if you name things the expected way, the pieces find each other with no configuration. That idea is called convention over configuration.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.