Middleware ایک hooks کا فریم ورک ہے جو ہر request اور response کو عام طور پر process کرتا ہے، ویب سرور اور آپ کے views کے درمیان بیٹھا ہوا۔ ہر middleware درخواست کو اندر آتے وقت اور جوابات کو باہر نکلتے وقت جانچ سکتا ہے/تبدیل کر سکتا ہے — authentication، security headers، sessions، اور logging جیسے cross-cutting concerns کے لیے موزوں۔
Middleware کے ذریعے request/response کا بہاؤ
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)
