Middleware is code that runs between the incoming HTTP request from the user and the outgoing HTTP response from the server, it acts as a layer that handles things before the request reaches a controller or after the response leaves the controller.
📦 Real-Life Analogy:
Imagine you own a restaurant, and every order goes through:
- 🛡️ The security guard (checks if the person has a reservation)
- 🎩 The host (guides them to the table)
- 📝 The waiter (takes the order)
- 👨🍳 The chef (prepares the meal)
- 🍽️ The waiter returns with the meal
Each one of these roles represents a Middleware—a layer that processes the request before the final result is served.
Example : Applying middleware pipeline inside Program.cs