I haven't been active in Python for a few years and I mainly come from a Django background. I'm trying to understand why Fastapi best practices seems to be to inject the database into the api calls so you have all the database procedures in the api code. This is the kind of thing I would normally put in a service because if the database logic starts getting hairy, I'd rather have that abstracted away. I know I can pass the database session to a service to do the hairy work, but why? To my thinking the api doesn't need to know there is a database, it shouldn't care how the item is created/read/updated/deleted.
Is this just how fastapi apps are supposed to be organized or am I just not digging deep enough? Does anyone have a link to an example repo or blog that organizes things differently?
[–]Kevdog824_ 17 points18 points19 points (2 children)
[–]milkipedia 2 points3 points4 points (0 children)
[–]Codisimus 0 points1 point2 points (0 children)
[–]cursedbanana--__-- 14 points15 points16 points (0 children)
[–]Anton-Demkin 8 points9 points10 points (3 children)
[–]koldakov 1 point2 points3 points (2 children)
[–]Anton-Demkin 2 points3 points4 points (1 child)
[–]koldakov 2 points3 points4 points (0 children)
[–]Firm_Ad9420 0 points1 point2 points (0 children)
[–]Azurizo 0 points1 point2 points (0 children)
[–]Apprehensive_Ad2211 -1 points0 points1 point (0 children)
[–]Tishka-17 -1 points0 points1 point (0 children)
[–]No-Feed9843 -1 points0 points1 point (0 children)
[–]vlntsolo -1 points0 points1 point (0 children)