Automated Action b00b44023a Add FastAPI REST API with SQLite database
- Set up project structure
- Add database models and SQLAlchemy setup
- Configure Alembic for migrations
- Create API endpoints for items
- Add health check endpoint
- Update documentation

generated with BackendIM... (backend.im)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-15 22:33:58 +00:00

2.5 KiB

Generic REST API Service

A modern, production-ready REST API service built with FastAPI and SQLite.

Features

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

Getting Started

Prerequisites

  • Python 3.8+
  • Git

Installation

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

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

API Documentation

Project Structure

.
├── alembic/                  # Database migrations
│   ├── versions/             # Migration versions
│   ├── env.py                # Alembic environment
│   └── script.py.mako        # Migration script template
├── app/                      # Application package
│   ├── api/                  # API endpoints
│   │   ├── v1/               # API v1
│   │   │   └── endpoints/    # API endpoints by resource
│   │   └── api.py            # API router setup
│   ├── core/                 # Core application code
│   │   └── config.py         # Application configuration
│   ├── crud/                 # CRUD operations
│   ├── database/             # Database setup
│   │   └── session.py        # DB session management
│   ├── models/               # SQLAlchemy models
│   └── schemas/              # Pydantic schemas
├── alembic.ini               # Alembic configuration
├── main.py                   # Application entry point
└── requirements.txt          # Project dependencies

API Endpoints

  • GET /api/v1/health: Health check endpoint
  • GET /api/v1/items: List all items
  • POST /api/v1/items: Create a new item
  • GET /api/v1/items/{item_id}: Get a specific item
  • PUT /api/v1/items/{item_id}: Update a specific item
  • DELETE /api/v1/items/{item_id}: Delete a specific item