A collection of FastAPI-REST-APIs and exercises demonstrating modern Python web API development, including RESTful services, authentication, database integration, and best practices.
This repository showcases my journey learning FastAPI - a modern, fast (high-performance) web framework for building APIs with Python 3.9+ based on standard Python type hints. This project demonstrates different aspects of API development from basic CRUD operations to advanced features like database integration, and real-time capabilities.
Why FastAPI?
- β‘ High performance - comparable to NodeJS and Go
- π Automatic interactive API documentation (Swagger UI)
- π Built-in data validation with Pydantic
- π Async/await support for concurrent operations
- π― Type hints for better IDE support and fewer bugs
- Projects Overview
- Features Demonstrated
- Technologies Used
- Installation
- Running the Projects
- API Documentation
- Project Structure
- Learning Resources
- Contact
Description: Simple REST API for managing items/resources
Endpoints: GET, POST, PUT, DELETE operations
Concepts:
- Path parameters and query parameters
- Request/Response models with Pydantic
- HTTP status codes
- API versioning
Description: API with PostgreSQL/MySQL database
Features:
- Database connection and session management
- ORM models with SQLAlchemy
- Database migrations with Alembic
- Relationship mapping (One-to-Many, Many-to-Many)
Concepts:
- Database design patterns
- Connection pooling
- Transaction management
Description: Production-ready Todo application API
Features:
- Complete CRUD operations
- Database persistence
- Input validation
- Error handling
- API documentation
Tech Stack: FastAPI + SQLAlchemy + PostgreSQL
- β RESTful API design principles
- β Automatic interactive documentation (Swagger UI & ReDoc)
- β Request/Response validation with Pydantic
- β Dependency injection system
- β Path operations and route handling
- β Query parameters, path parameters, request body
- β Error handling and custom exceptions
- β Status codes and response models
- πΎ Database integration (SQLAlchemy ORM)
- π¦ Middleware (CORS, rate limiting, logging)
- π API versioning
- π§ͺ Testing with pytest
- π API documentation best practices
| Technology | Purpose |
|---|---|
| FastAPI | Web framework |
| Uvicorn | ASGI server |
| Pydantic | Data validation |
| SQLAlchemy | ORM for database |
| PostgreSQL/MySQL | Relational database |
- Python 3.9 or higher
- pip (Python package manager)
- PostgreSQL/MySQL (for database projects)
- Git
- Clone the repository
https://github.com/nushant22/FastAPI-REST-APIs.git
cd FastAPI-REST-APIs- Create virtual environment
# On Windows
python -m venv venv
venv\Scripts\activate
# On macOS/Linux
python3 -m venv venv
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Set up environment variables
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# DATABASE_URL=postgresql://user:password@localhost/dbname- Set up database (for projects requiring database)
# Run migrations
alembic upgrade head# Navigate to specific project folder
cd project_folder_name
# Run with uvicorn
uvicorn main:app --reload
# Or specify host and port
uvicorn main:app --host 0.0.0.0 --port 8000 --reload- API: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Each project includes automatic interactive documentation:
Visit /docs endpoint to:
- View all available endpoints
- Test API calls directly in browser
- See request/response schemas
- View authentication requirements
# Health check
GET /health
# User authentication
POST /auth/register
POST /auth/login
POST /auth/refresh
# CRUD operations
GET /api/v1/items # Get all items
GET /api/v1/items/{id} # Get specific item
POST /api/v1/items # Create new item
PUT /api/v1/items/{id} # Update item
DELETE /api/v1/items/{id} # Delete item
POST /api/v1/items
// Request Body
{
"name": "Sample Item",
"description": "This is a sample item",
"price": 29.99,
"is_available": true
}
// Response (201 Created)
{
"id": 1,
"name": "Sample Item",
"description": "This is a sample item",
"price": 29.99,
"is_available": true,
"created_at": "2026-02-16T10:30:00Z"
}FASTAPI-REST-APIs/
β
βββ frontend/ # Frontend (React)
β βββ public/
β β βββ index.html # HTML entry point
β β βββ manifest.json # Web app metadata
β β
β βββ src/
β β βββ App.js # Root React component
β β βββ App.css # Global app styles
β β βββ index.js # React DOM entry
β β βββ index.css # Base CSS styles
β β βββ TaglineSection.js # Tagline UI component
β β βββ TaglineSection.css # Tagline component styles
β β
β βββ package.json # Frontend dependencies & scripts
β βββ package-lock.json # Locked dependency versions
β
βββ .gitignore # Git ignore rules
βββ main.py # FastAPI app entry point
βββ database.py # Database connection setup
βββ models.py # SQLAlchemy models
βββ database_models.py # Database schema definitions
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
Through these FastAPI projects, I've gained:
- β Modern Python web development skills
- β RESTful API design principles
- β Database design and ORM usage
- β API testing and documentation
Contributions are welcome! If you have improvements or new examples:
- Fork the repository
- Create a feature branch (
git checkout -b feature/NewExample) - Commit your changes (
git commit -m 'Add new example') - Push to the branch (
git push origin feature/NewExample) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Nushant Ghimire
- LinkedIn: nushant-ghimire-861b87325
- GitHub: @nushant22
- Email: [nushantghimire22@gmail.com]
- FastAPI creator SebastiΓ‘n RamΓrez
- FastAPI community for excellent documentation
- Stack Overflow community for troubleshooting help
β If you find this repository helpful, please give it a star!
π Building APIs with FastAPI? Let's connect and share knowledge!
Last Updated: February 2026