Automated Action 00174fd9dc Create REST API with FastAPI and SQLite
- Set up project structure with FastAPI
- Configure SQLite database with SQLAlchemy
- Set up Alembic for migrations
- Create Item model and schema
- Implement CRUD operations
- Add health endpoint

generated with BackendIM... (backend.im)
2025-05-13 21:57:29 +00:00

2.0 KiB

Generic REST API Service

A RESTful API service built with FastAPI and SQLite database.

Features

  • FastAPI framework with automatic Swagger/ReDoc documentation
  • SQLAlchemy ORM for database management
  • Alembic for database migrations
  • SQLite database
  • Pydantic models for data validation
  • CRUD operations for resources
  • Health check endpoint

Project Structure

.
├── alembic/                 # Database migration scripts
├── app/                     # Application code
│   ├── api/                 # API endpoints
│   │   └── v1/              # API version 1
│   ├── core/                # Core functionality
│   ├── crud/                # CRUD operations
│   ├── db/                  # Database setup
│   ├── models/              # SQLAlchemy models
│   └── schemas/             # Pydantic schemas
├── alembic.ini              # Alembic configuration
├── main.py                  # Application entry point
└── requirements.txt         # Project dependencies

Installation

  1. Clone the repository:
git clone <repository-url>
cd genericrestapiservice
  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

Running the Application

Start the application using Uvicorn:

uvicorn main:app --reload

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

Documentation is available at:

API Endpoints

Health Check

  • GET /api/v1/health: Check API health

Items Resource

  • GET /api/v1/items: List all items
  • POST /api/v1/items: Create a new item
  • GET /api/v1/items/{id}: Get a specific item
  • PUT /api/v1/items/{id}: Update an item
  • DELETE /api/v1/items/{id}: Delete an item