Prerequisites: Basic Python knowledge, understanding of REST APIs, Docker installed
Duration: 1 hour
Difficulty: Beginner to Intermediate
- Part 1: Foundation β You are here
- Part 2: FastAPI Deep Dive
- Part 3: DocumentDB Superpowers
- Part 4: Production Ready
# Clone the repository
git clone https://github.com/documentdb/fast-api-sample.git
cd fast-api-sample
# Open in VS Code
code .# Pull and start DocumentDB
docker pull ghcr.io/documentdb/documentdb/documentdb-local:latest
docker tag ghcr.io/documentdb/documentdb/documentdb-local:latest documentdb
# Run DocumentDB container
docker run -dt -p 10260:10260 --name documentdb-container documentdb --username admin --password password123Verify it's running:
docker ps
# You should see documentdb-container running on port 10260Use the DocumentDB VS Code extension using your connection string:
mongosh "mongodb://USERNAME:PASSWORD@localhost:10260/?authMechanism=SCRAM-SHA-256&tls=true&tlsAllowInvalidCertificates=true"- Click on the drop-down next to your local connection and select "Create Database..."
- Enter database name and confirm (suggested: ecommerce)
- Click on the drop-down next to your created database and select "Create Collection..."
- Create your collections,
productsandcustomersand confirm.
Import data to DocumentDB
- For each collection, click the
Importbutton on the top-right corner. - Import the
/scripts/sample_customers.jsonfile in thecustomerscollection and/scripts/sample_products.jsonfile in theproductscollection.
cp .env.example .envIn the .env file, add your connection string, database name, and DocumentDB credentials.
Afterwards, install the requirements needed for the data to migrate to the frontend.
cd backend
pip install -r requirements.txtcd ..
docker-compose up -dTest the API:
- Open sample: http://localhost
- Open browser: http://localhost:8000/docs
- Test the health endpoint: http://localhost:8000/health
β Checkpoint: You should see the Swagger UI with all endpoints documented.
What you've accomplished:
- β Set up DocumentDB container locally
- β Loaded sample e-commerce data
- β Configured FastAPI application
- β Verified the API is running with Swagger UI
What you've learned:
- How to run DocumentDB in Docker
- How to connect FastAPI to DocumentDB
- How to use the DocumentDB VS Code extension
- Basic API testing with Swagger UI
Next Steps: Continue to Part 2: FastAPI Deep Dive to learn about:
- Async/await patterns with database operations
- Request lifecycle and performance
- Pydantic + Beanie integration
- Building a complete Reviews feature from scratch