Middleware hooks का एक framework है जो प्रत्येक request और response को वैश्विक रूप से process करता है, web server और आपके views के बीच बैठते हुए। प्रत्येक middleware अंदर आते समय requests और बाहर जाते समय responses का निरीक्षण/संशोधन कर सकता है — authentication, security headers, sessions, और logging जैसे cross-cutting concerns के लिए आदर्श।
middleware के माध्यम से request/response flow
Request → MW1 → MW2 → MW3 → VIEW
Response ← MW1 ← MW2 ← MW3 ← VIEW
Middleware wraps the view like layers of an onion:
- on the way IN (request): top-to-bottom
- on the way OUT (response): bottom-to-top (reverse order)
