Skip to content

Modern REST API development with FastAPI showcasing CRUD operations, JWT authentication, database integration, WebSockets, and production ready best practices. High performance Python web APIs with automatic documentation.

Notifications You must be signed in to change notification settings

nushant22/FastAPI-REST-APIs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚑ FastAPI-REST-APIs - Modern REST API Development

A collection of FastAPI-REST-APIs and exercises demonstrating modern Python web API development, including RESTful services, authentication, database integration, and best practices.

FastAPI Python License

🎯 About

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

πŸ“‹ Table of Contents

πŸš€ Projects Overview

1. Basic CRUD API

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

2. Database Integration (SQLAlchemy)

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

3. Todo API with Full Features

Description: Production-ready Todo application API
Features:

  • Complete CRUD operations
  • Database persistence
  • Input validation
  • Error handling
  • API documentation

Tech Stack: FastAPI + SQLAlchemy + PostgreSQL


✨ Features Demonstrated

Core FastAPI Features

  • βœ… 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

Advanced Features

  • πŸ’Ύ Database integration (SQLAlchemy ORM)
  • 🚦 Middleware (CORS, rate limiting, logging)
  • πŸ“Š API versioning
  • πŸ§ͺ Testing with pytest
  • πŸ“ API documentation best practices

πŸ› οΈ Technologies Used

Technology Purpose
FastAPI Web framework
Uvicorn ASGI server
Pydantic Data validation
SQLAlchemy ORM for database
PostgreSQL/MySQL Relational database

πŸ“¦ Installation

Prerequisites

  • Python 3.9 or higher
  • pip (Python package manager)
  • PostgreSQL/MySQL (for database projects)
  • Git

Setup Instructions

  1. Clone the repository
https://github.com/nushant22/FastAPI-REST-APIs.git
cd FastAPI-REST-APIs
  1. Create virtual environment
# On Windows
python -m venv venv
venv\Scripts\activate

# On macOS/Linux
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Set up environment variables
# Create .env file
cp .env.example .env

# Edit .env with your configuration
# DATABASE_URL=postgresql://user:password@localhost/dbname
  1. Set up database (for projects requiring database)
# Run migrations
alembic upgrade head

πŸš€ Running the Projects

Start the development server

# 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

Access the application

πŸ“š API Documentation

Each project includes automatic interactive documentation:

Swagger UI (OpenAPI)

Visit /docs endpoint to:

  • View all available endpoints
  • Test API calls directly in browser
  • See request/response schemas
  • View authentication requirements

Example API Endpoints

# 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

Sample Request/Response

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"
}

πŸ“‚ Project Structure

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

πŸ“– Learning Resources

Official Documentation

Tutorials I Found Helpful

Video Courses

πŸŽ“ Key Learnings

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

🀝 Contributing

Contributions are welcome! If you have improvements or new examples:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/NewExample)
  3. Commit your changes (git commit -m 'Add new example')
  4. Push to the branch (git push origin feature/NewExample)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ“§ Contact

Nushant Ghimire

πŸ™ Acknowledgments

  • 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

About

Modern REST API development with FastAPI showcasing CRUD operations, JWT authentication, database integration, WebSockets, and production ready best practices. High performance Python web APIs with automatic documentation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published