Middleware - airtype/craft-httpmessages GitHub Wiki
What is middleware?
A middleware a class is primarily responsible for receiving a Request
and Response
object and returning a Response
object. Upon receiving a Request
and Response
object, a middleware can decorate the objects according to the needs of the middleware.
A middleware is also aware of the next middleware in the middleware stack, and is responsible for calling that middleware, passing the decorated Request
and Response
objects.
For each route defined in the httpmessages.php
config, a stack of middleware should be defined as well.
Above is an example of Request
and Response
objects being passed through a stack of middleware. The ?
in the middleware represents an opportunity for the middleware to decorate the Request
and Response
object, before passing the objects to the next middleware. Likewise, each middleware has the opportunity to decorate the Response
object that is returned by the previous middleware.
[Relay] (http://relayphp.com) is utilized for processing the middleware collection. For a more detailed explanation of how it implements middleware, please refer to its documentation.