FastAPI REST API

This is a FastAPI-based REST API application that provides CRUD operations for managing items.

Features

  • FastAPI framework for high-performance API development
  • SQLAlchemy ORM with SQLite database
  • Alembic for database migrations
  • Pydantic for data validation
  • CRUD operations for items
  • Health check endpoint
  • Interactive API documentation

Project Structure

├── app/                    # Application package
│   ├── api/                # API endpoints
│   │   ├── endpoints/      # API route handlers
│   │   │   └── items.py    # Items API endpoints
│   ├── core/               # Core application modules
│   │   ├── app.py          # FastAPI application factory
│   │   └── config.py       # Application configuration
│   ├── db/                 # Database related modules
│   │   ├── base.py         # Import all models for Alembic
│   │   ├── base_class.py   # Base class for SQLAlchemy models
│   │   └── session.py      # Database session setup
│   ├── models/             # SQLAlchemy models
│   │   └── item.py         # Item model
│   └── schemas/            # Pydantic schemas
│       └── item.py         # Item schemas
├── migrations/             # Alembic migrations
│   ├── versions/           # Migration scripts
│   ├── env.py              # Alembic environment configuration
│   └── script.py.mako      # Alembic script template
├── alembic.ini             # Alembic configuration
├── main.py                 # Application entry point
└── requirements.txt        # Project dependencies

Setup and Installation

  1. Clone the repository:

    git clone <repository-url>
    cd genericrestapi-3gclpr
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Run the application:

    uvicorn main:app --host 0.0.0.0 --port 8000 --reload
    
  4. Access the API documentation:

API Endpoints

Health Check

  • GET /health: Check the health status of the API

Items API

  • POST /api/v1/items: Create a new item
  • GET /api/v1/items: List all items (with pagination)
  • GET /api/v1/items/{item_id}: Get a specific item by ID
  • PUT /api/v1/items/{item_id}: Update an item
  • DELETE /api/v1/items/{item_id}: Delete an item

Database Migrations

Create a new migration:

alembic revision --autogenerate -m "description"

Apply migrations:

alembic upgrade head

Revert migrations:

alembic downgrade -1
Description
Project: Generic REST API
Readme 44 KiB
Languages
Python 95.9%
Mako 4.1%