Kludex / fastapi-tips

FastAPI Tips by The FastAPI Expert!
2.11k stars 79 forks source link

🔀 Add "Use a main router" advice #5

Open p1-dta opened 6 months ago

p1-dta commented 6 months ago

I think this repository is a good idea!

Here is my first contribution, more oriented around code and file layout than technical stuff. However, this approach has been very helpful to me and teammates over the past few years.

What do you think?

Kludex commented 6 months ago

That's not exactly what I would recommend (naming wise).

I prefer to call the directory api/, and have a directory structure where the __init__.py contains the APIRouter, with the prefix based on the directory it is in.

p1-dta commented 6 months ago

@Kludex to clarify this point, the fastapi.FastAPI object ("app") is located in project/app.py, and the main router in project/api/__init__.py ? What name would you prefer ? TBH I never took the time to think of a better name. What do you suggest?

p1-dta commented 5 months ago

@Kludex bump?