This project demonstrates a FastAPI application using Beanie ODM (Object Document Mapper) for MongoDB. The project is containerized using Docker and Docker Compose for easy setup and deployment.
- app/server/models/product_review.py: Defines the
ProductReview
andUpdateProductReview
models usingBeanie
andPydantic
. - app/server/routes/product_review.py: Contains the
API routes
for handling product reviews. - app/server/app.py: The main
FastAPI
application setup, includingroute inclusion
anddatabase initialization
. - app/server/database.py: Contains the
database initialization logic
. - main.py: The entry point for running the
Uvicorn server
. - Dockerfile: The
Dockerfile
for building the FastAPI application image. - docker-compose.yml:
Docker Compose file
for setting up theFastAPI
andMongoDB services
. - requirements.txt: Python dependencies required for the project.
Docker Desktop
installed and up and running on your machine.
-
Clone the repository:
git clone https://github.com/SaadARazzaq/Product-Reviews-API cd fastapi-beanie
-
Build and start the Docker containers:
docker-compose up --build
-
The FastAPI application will be available at
http://localhost:8000
.
{
"name": "Saad Abdur Razzaq",
"title": "MacBook Air M2",
"rating": 5.0,
"review": "Best Laptop in the world",
"date": "2023-06-30T12:34:56.789Z"
}
{
"name": "Taha Abdur Razzaq",
"title": "HP Victus 16",
"rating": 5.0,
"review": "Worst Laptop in the world",
"date": "2023-06-30T12:34:56.789Z"
}
- Ensure MongoDB is running and accessible for the FastAPI application to function correctly.
- The mongo_url in app/server/database.py is set to connect to a MongoDB instance at host.docker.internal.
This project was made with π by Saad Abdur Razzaq