This project is my rack app learning playground. Nothing more. Nothing less.
The Learning Steps:
- In this you will know what rack is all about
- In this you will learn how simpler rack app can be
- Here you will get to understand rackup gem utility.
- What Rack::Builder#run does?
- What Rack::Builder#use does?
- What Rack::Builder#map does?
- Understanding rackup holistically
- What next?
- Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. Rack provides an interface between different web servers and your framework/application. Making it very simple for your framework/application to be compatible with any webserver that supports Rack – Phusion Passenger, Litespeed, Mongrel, Thin, Ebb, Webrick to name a few.
- Practically speaking, you can divide “Rack” in two parts :
- Rack specification specifies how exactly a Rack application and the web server should communicate : A Rack application is an Ruby object (not a class) that responds to call. It takes exactly one argument, the environment and returns an Array of exactly three values: The status, the headers, and the body.
- Rack gem is a collection of utilities and facilitating classes, to make life easier for anyone developing Rack applications. It includes basic implementations of request, response, cookies & sessions. And a good number of usefult middlewares. (For this, you have to install the rack gem.)
- Rack::Builder implements a small DSL to iteratively construct Rack applications. Rack::Builder is the thing that glues various Rack middlewares and applications together and convert them into a single entity/rack application. A good analogy is comparing Rack::Builder object with a stack, where at the very bottom is your actual rack application and all middlewares on top of it, and the whole stack itself is a rack application too.
- Rack::Builder instance methods you should care about:
- Rack::Builder#run specifies the actual rack application you are wrapping with Rack::Builder
- Rack::Builder#use adds a middleware to the rack application stack
- Rack::Builder#map mounts a stack of rack application/middlewares the specified path or URI and all the children paths under it. When you have multiple map blocks, URIs are tried from longest length to shortest length.
- Makes it possible to use multiple frameworks for the same application, provided there is no class collision. Rails and sinatra integration is a good example of this.
Git recommends adding README.md
The page that details on the markup supported: https://github.com/github/markup#readme