Reputation: 682
I'm working with fastapi and suppose I have registered 2 middlewares called A and B (for example, they can add to each request the connection to a database) . Suppose also that I have 2 endpoints, and the first one only need A middleware and the second one only need B middleware. I used dependencies to establish the needs of each endpoint . When I use the first endpoint, the request is equiped with the result of both middlewares A and B, I want to restrict the effect of middlewares only when they are needed, I thought that was done using dependencies. How can I do that?. Thank you!!
Upvotes: 1
Views: 505
Reputation: 22459
If I understand your question correctly, the practice seems to either create custom logic within your middleware (e.g. check which path/route was invoked), or use the advanced feature of declaring custom Request/APIRoute objects as described by the docs
Upvotes: 1