
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
-
Clone the repository:
git clone <repository-url> cd genericrestapi-3gclpr
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
-
Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Health Check
GET /health
: Check the health status of the API
Items API
POST /api/v1/items
: Create a new itemGET /api/v1/items
: List all items (with pagination)GET /api/v1/items/{item_id}
: Get a specific item by IDPUT /api/v1/items/{item_id}
: Update an itemDELETE /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
Languages
Python
95.9%
Mako
4.1%