Build a Middleware Pipeline

Chain of Responsibility pattern

Challenge 2 of Decouple EventsIntermediate~55 minFree

Every web framework runs each request through a pipeline of middleware: authenticate, rate-limit, then dispatch to the app. That pipeline is the Chain of Responsibility pattern. You will build a handler base that passes requests down a chain, add auth and rate-limit stages that can short-circuit the pipeline, write a terminal app handler, and finish with a builder that wires any list of handlers into a chain, the exact machinery behind Express and Django middleware.

5 steps

  1. 1The Handler Base
  2. 2The Auth Handler
  3. 3The App Handler
  4. 4The Rate Limit Handler
  5. 5The Chain Builder
Start step 1