Chapter 18. Rack-based applications
This chapter covers
- Building a basic Rack application
- Tying together Rack applications
- Mounting a Rack app within a Rails app
- Using Rack middleware to alter server response
So far, this book has primarily focused on how to work with pieces of the Rails framework, such as application and engines. In this chapter, we’ll look at how you can use Rack-based applications to respond more quickly than what you’d otherwise be capable of with your main application.
Rack is the underlying web server framework that powers the underlying request/response cycle found in Rails, but it isn’t a part of Rails itself. It’s completely separate, with Rails requiring the parts of Rack it needs. When your application is running, it’s running through a web server. When your web server receives a request, it will pass it off to Rack, as shown in figure 18.1.
Rack then determines where to route this request, and in this case it has chosen to route to a specific application stack. The request passes through a series of pieces called middleware (covered in the final section of this chapter) before arriving at the application itself. The application will then generate a response and pass it back up through the stack to Rack, and then Rack will pass it back to the server, which will finally pass it back to the browser. All of this happens in a lightning quick fashion.