Dependency Bundle
In order to avoid redundant or outside of logic code, FastJWT provides a way to inject a dependency bundle in route's function with FastJWT.get_dependency
.
FastJWT.get_dependency
returns a FastJWTDeps
instance that is tied to the request and response of the route. This object includes all the dependency available in FastJWT
To show how FastJWTDeps
can help reduce code complexity let's focus on authentication via Cookies
The main difference in those 2 snippets is the implicit context grapped by FastJWTDeps
. You don't need to generate get access to the request or create a response object to set/unset cookies for example. This allows for less code, but mostly prevents you to handle fastapi.Response
objects that might be outside of your function logic.