Middleware are just like the filter funnel which filters the HTTP request inside any application. Any request before enter into application must needs to pass through the barrier of middleware which application contains.
Middlewares basically used to filter the authenticated request in application. By the help of which we can detect which route is valid or invalid. Apart from this, we have several other examples.