Comparison
Chain of responsibilityvsMiddleware
Chain of responsibility
the request went to the first handler, which passed it on, and somewhere down the line something answered it.
Passing a request along a sequence of handlers until one of them deals with it, so the sender does not know which will. HTTP middleware stacks, servlet filters and event bubbling in the DOM are all this pattern. Its characteristic failure is silence: if no handler takes the request, nothing happens and nothing says so, which is why a terminal handler that raises is nearly always worth adding.
Full entry →Middleware
each function takes the next one and returns a new one, so authentication wrapped logging wrapped the actual handler.
A composable wrapper around a handler that can act before it, after it, or instead of it, stacked into a pipeline. It is the decorator pattern written as functions and assembled as a chain of responsibility, which is why it is the shape every web framework converged on independently. Its recurring difficulty is order: authentication before rate limiting and rate limiting before authentication are different products.
Full entry →