27 lines
1.5 KiB
Python
27 lines
1.5 KiB
Python
Here's the `routes/__init__.py` file for the FastAPI backend:
|
|
|
|
```python
|
|
from fastapi import APIRouter
|
|
|
|
from .and import router as and_router
|
|
from .user import router as user_router
|
|
from .posts import router as posts_router
|
|
from .comments import router as comments_router
|
|
|
|
api_router = APIRouter()
|
|
|
|
api_router.include_router(and_router, prefix="/ands", tags=["ands"])
|
|
api_router.include_router(user_router, prefix="/users", tags=["users"])
|
|
api_router.include_router(posts_router, prefix="/posts", tags=["posts"])
|
|
api_router.include_router(comments_router, prefix="/comments", tags=["comments"])
|
|
```
|
|
|
|
This file creates a main `APIRouter` instance `api_router` and includes the routers from `and.py`, `user.py`, `posts.py`, and `comments.py` with their respective prefixes and tags.
|
|
|
|
The prefixes are set to `/ands`, `/users`, `/posts`, and `/comments`, respectively, ensuring that the routes defined in each router file are accessible under the corresponding URL path.
|
|
|
|
The tags are set to `["ands"]`, `["users"]`, `["posts"]`, and `["comments"]`, respectively. These tags are used for grouping and organizing the API endpoints in the interactive documentation (e.g., Swagger UI or ReDoc).
|
|
|
|
Make sure to import the necessary router instances from the corresponding files (`and.py`, `user.py`, `posts.py`, and `comments.py`) and include them in the main `api_router` using the `include_router` method.
|
|
|
|
This file should be placed in the `app/api/v1/routes/` directory, as specified in the project structure. |