How to understand rails request and response flow?

I would like to know about rails architecture that how does rails core work for incoming and outgoing request call.

Or web server (puma) send user request to routes so how does it I think it should deep dive into rack and action pack and all about it. Please provide me Idea as developer.

This should help you.

1 Like

helpful, thank you .

Hello rails6learner,

If you’re learning Rails, there is an overview of the request-response cycle in “Agile Web Development with Rails 6” (Pragmatic Bookshelf).

If what you want is to optimize Rails properly, then I would recommend “The Complete Guide to Rails Performance” by Nate Bergopek.

If you have time to look into a lot of detail, then “Crafting Rails 4 Applications” by José Valim provides quite a good overview of how Rails works under the hood, with worked examples of how to extend the functionality. Other than that take a look at the ActionPack source code, it contains ActionDispatch and the Router, which handle incoming requests, and ActionController which serves as the base for application code which sanitizes parameters, interacts with ActiveModel, and handles how and in which format the response is rendered, as well as the HTTP status code returned to the browser. If you really want to look into Puma and Rack, I would recommend setting some time aside to take a look at them separately. Think of Rack as the API layer between Rails and Puma.

-Peter

By the way, this isn’t an endorsement of those books, they are the references I use myself, and are higher quality than free blog posts!

3 Likes

see the puma gem source code for details

Np. If you want to dive deeper I would recommend this course http://owningrails.com/