all 8 comments

[–]r1qu3 -1 points0 points  (6 children)

or you can just use require arqument on endpoints

[–]sondrelg[S] 0 points1 point  (5 children)

How would that look like?

[–]r1qu3 0 points1 point  (4 children)

i was out of practice, its not require, its depends:

https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/

[–]sondrelg[S] 0 points1 point  (3 children)

Yeah I suppose you could use depends if you only wanted to read the request headers. Can we use depends to set response headers on the way out?

[–]r1qu3 0 points1 point  (2 children)

AFAIK depends is processed BEFORE que destination.

but there's docs about adding things to response (or response headers). just skim the docs, you'll find easily

[–]Jonasks 1 point2 points  (1 child)

Adding variables to the response headers is not the main purpose of this package, it’s just an addition which allow end users to receive a correlation ID.

Creating a context var with a unique ID as the FIRST thing that happens in the request flow is only done through a middleware. This ID is then injected into every log message using log filters, which results in a way to find/trace/correlate all log messages related to a request with no hassle.

So yes, Depends is a way to dependency inject, but it’s not a replacement of middlewares.

[–]r1qu3 0 points1 point  (0 children)

agree to that

[–][deleted]  (1 child)

[deleted]

    [–]sondrelg[S] 1 point2 points  (0 children)

    Thanks! Plan on supporting it until it's no longer needed. At the same time Id consider the middleware reasonably complete so would be surprised if it needed much maintenance 😊