Skip to content
Discussion options

You must be logged in to vote

You can call the route functions directly, but if you do so, you lose the dependency injection. In particular, if the functions have default values of a type like Query(...) or Depends(dependency_func), you have to provide values, as the "defaults" are not actually valid, and are not substituted based on the request unless called by FastAPI.

As you noted, the easiest way to accomplish this might be to separate the shared business logic into a reusable function.


There are other patterns you could use, such as a class-based dependency, that might enable you to refactor the code in a way you find more reusable, but it would probably require a larger refactor than would be ideal. But right n…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by sschiessl-bcp
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
4 participants
Converted from issue

This discussion was converted from issue #874 on February 28, 2023 11:13.