The controller might interact with the data layer directly, when a route is used as an endpoint to trigger some data, a controller is used to respond with a JSON object. The Controller might talk immediately to the database without using Block.

What is a Request?

A request is a communicative message that is transmitted between the client, or web browsers, to the servers. This request is essential in providing the user with the correct and preferred web pages that will be displayed on the user’s interface.

The server receives the request by the client that will result in the server sending back a response to the client. The response might be a web page, image, JSON, XML, or interactive feature.

Where does Magento 2 receive a request?

Magento has an entry point, where the request processing starts on the platform side. The entry point for Magento standard requests ispub/index.php file.

The logic inside this file loads a bootstrap then creates and runs the application.

What is Bootstrapping?

The bootstrap is responsible for auto-loading and initial application running. Autoloading is a logic that allows to connect all files in the application together and use code from one file in another one. How does the auto-loader work?

<aside> ➡️ Bootstrap and Magento Application initialization happens once and isn't part of every request.

</aside>

Where does the Request go?

Once the main components have been registered, the routing logic takes place. The routing system tries to recognize the request by its URL, then loads the corresponding part of the platform that can handle the request. The routing flow is controlled by a front controller class.

Untitled

  1. The FrontController class searches through a list of routers, provided by the RouterList class until it matches one that can process a request.
  2. When the FrontController finds a matching router, it dispatches the request to an action class returned by the router.
  3. If the FrontController cannot find a router to process a request, it uses the default router.

What Magento areas are involved?

Magento 2 handles different request types differently and each one might lead to a different path.