Automated Action 66f95ea88e Fix database path for standalone environment
- Modified database connection to use project-relative paths
- Updated Alembic configuration to dynamically use the SQLAlchemy URL
- Added a root endpoint for easy testing
- Fixed imports in migration environment
2025-05-18 19:15:35 +00:00
2025-05-18 16:42:02 +00:00

Generic REST API Service

A RESTful API built with FastAPI and SQLite.

Features

  • FastAPI framework for high performance
  • SQLAlchemy ORM with SQLite database
  • Alembic for database migrations
  • Pydantic for data validation
  • CRUD operations for resources
  • API documentation (Swagger UI and ReDoc)
  • Health check endpoint

Project Structure

.
├── alembic.ini                  # Alembic configuration
├── app                           
│   ├── api                      # API endpoints
│   │   ├── api.py              # Main API router
│   │   ├── endpoints           # API endpoint modules
│   │       ├── health.py       # Health check endpoint
│   │       └── items.py        # Items CRUD endpoints
│   ├── core                    # Core application components
│   │   └── config.py           # Application settings
│   ├── crud                    # CRUD operations
│   │   └── item.py             # Item CRUD
│   ├── db                      # Database setup
│   │   └── database.py         # DB connection, session
│   ├── models                  # SQLAlchemy models
│   │   └── item.py             # Item model
│   ├── schemas                 # Pydantic schemas
│   │   └── item.py             # Item schemas
│   └── storage                 # Storage for DB and files
│       └── db                  # Database storage
├── migrations                  # Alembic migrations
│   ├── env.py                  # Alembic environment
│   ├── script.py.mako          # Migration script template
│   └── versions                # Migration versions
│       └── 001_create_items_table.py  # First migration
├── main.py                     # Application entry point
└── requirements.txt            # Project dependencies

Installation

Prerequisites

  • Python 3.8+
  • pip

Setup

  1. Clone the repository:
git clone <repository-url>
cd genericrestapiservice-e7xfpj
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. Start the application:
uvicorn main:app --reload

The API will be available at http://localhost:8000.

API Documentation

API Endpoints

  • Health Check: GET /api/v1/health
  • List Items: GET /api/v1/items
  • Create Item: POST /api/v1/items
  • Get Item: GET /api/v1/items/{item_id}
  • Update Item: PUT /api/v1/items/{item_id}
  • Delete Item: DELETE /api/v1/items/{item_id}

Development

Adding a New Endpoint

  1. Create a new module in app/api/endpoints/
  2. Define your routes using FastAPI's router
  3. Add your new router to app/api/api.py

Adding a New Model

  1. Define your SQLAlchemy model in app/models/
  2. Define the Pydantic schemas in app/schemas/
  3. Create CRUD utilities in app/crud/
  4. Generate a migration: alembic revision -m "Add new model"
  5. Edit the migration file in migrations/versions/
  6. Apply the migration: alembic upgrade head
Description
Project: Generic REST API Service
Readme 44 KiB
Languages
Python 96.5%
Mako 3.5%