Rails isn't magic, but sometimes it feels like it. To get a better understanding of Rails' MVC web framework, I built a "lite" version of Rails from scratch.
Below are some noteworthy facets of this project:
WEBRick Server: server.rb The server utilizes Ruby's WEBRick library to provide the interface for receiving HTTP requests and sending responses.
HTTPRequestobjects to fill out an
HTTPResponseobject. It sets the
bodyof the response and returns the response with rendered content.
Sessionallows us to set and store
HTTPCookies for the user's session.
Paramsallows us to receive and parse params from either the router's match of the URL, the query string, or the request body.
Routerkeeps track of multiple routes, including the matched URL patterns, the HTTP method (GET, POST, PUT, DELETE), the controller class the route maps to, and the action to be invoked.