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.
What is the purpose of Rack in rails?
As per Rack, it provides a minimal interface between web servers that support Ruby and Ruby frameworks. In simple terms, Rack sits between the ruby based application and web server helping them to interact with each other.
How does Rack work?
Using Rack you can write a Rack Application. Rack will pass the Environment hash (a Hash, contained inside a HTTP request from a client, consisting of CGI-like headers) to your Rack Application which can use things contained in this hash to do whatever it wants.