This repository contains a collection of advanced FastAPI tutorials covering various aspects of modern API development.
-
API Versioning (
22apiversioning/
)- Version-specific routers and models
- Prometheus metrics integration
- Request/response logging
- Health check endpoints
-
GraphQL Integration (
23graphql/
)- Strawberry GraphQL integration
- Queries and mutations
- GraphQL types and schemas
- CRUD operations through GraphQL
-
WebSocket Security (
24websocketsecurity/
)- Secure WebSocket connections with JWT
- User management and password hashing
- SQLAlchemy integration
- Real-time message broadcasting
-
Microservices and API Gateway (
25microservices/
)- Service discovery and routing
- Circuit breaker pattern
- Load balancing
- Health checks and CORS
-
Event-Driven Architecture (
26eventdriven/
)- RabbitMQ integration
- Event publishing and consuming
- Message persistence
- Background tasks
-
Distributed Tracing (
27distributedtracing/
)- OpenTelemetry integration
- Jaeger tracing
- Prometheus metrics
- Analytics endpoints
-
CI/CD and Testing (
28cicdtesting/
)- Unit and integration tests
- GitHub Actions workflow
- Docker configurations
- Code coverage reporting
-
API Gateway Security and Load Testing (
29securityloadtesting/
)- Rate limiting
- IP whitelisting/blacklisting
- Security middleware
- Load testing with Locust
- Python 3.9+
- FastAPI 0.68.0+
- Additional dependencies in
requirements.txt
- Clone the repository:
git clone <repository-url>
cd fastapi-tutorials
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
Each tutorial is contained in its own directory with a dedicated Python file. To run any example:
- Navigate to the tutorial directory:
cd <tutorial-directory>
- Run the FastAPI application:
uvicorn <filename>:app --reload
For example, to run the API versioning example:
cd 22apiversioning
uvicorn 22apiversioning:app --reload
To run the tests:
pytest
For coverage report:
pytest --cov=app --cov-report=html
To run load tests with Locust:
cd 29securityloadtesting
locust -f 29securityloadtesting.py
Then open http://localhost:8089 in your browser.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.