
- 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>
2.5 KiB
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
- Clone the repository:
git clone <repository-url>
cd genericrestapiservice
- Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
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 endpointGET /api/v1/items
: List all itemsPOST /api/v1/items
: Create a new itemGET /api/v1/items/{item_id}
: Get a specific itemPUT /api/v1/items/{item_id}
: Update a specific itemDELETE /api/v1/items/{item_id}
: Delete a specific item