
- Set up project structure with app modules - Configure SQLite database connection - Set up Alembic for database migrations - Implement Item model with CRUD operations - Create API endpoints for items management - Add health check endpoint - Add API documentation - Add comprehensive README
REST API Service
A modern, lightweight REST API service built with FastAPI and SQLite.
Features
- FastAPI Framework: High performance, easy to learn, fast to code
- SQLite Database: Simple, reliable, and zero-configuration database
- Alembic Migrations: Database versioning and migration management
- Pydantic Models: Data validation and schema definition
- API Documentation: Interactive OpenAPI docs with Swagger and ReDoc
- Health Check Endpoint: Monitoring and service status reporting
- CRUD Operations: Complete Create, Read, Update, Delete functionality
- SQLAlchemy ORM: Object-Relational Mapping for database interactions
Getting Started
Prerequisites
- Python 3.8 or newer
- pip (Python package installer)
Installation
- Clone the repository:
git clone <repository-url>
cd <repository-directory>
- Install dependencies:
pip install -r requirements.txt
- Initialize the database:
alembic upgrade head
- Start the server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
Once the server is running, you can access:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Health Check
GET /api/v1/health
: Check the service health status
Items
GET /api/v1/items
: List all itemsPOST /api/v1/items
: Create a new itemGET /api/v1/items/{id}
: Get a specific itemPUT /api/v1/items/{id}
: Update a specific itemDELETE /api/v1/items/{id}
: Delete a specific item
Project Structure
.
├── alembic.ini # Alembic configuration
├── app # Application package
│ ├── api # API endpoints
│ │ ├── deps.py # Dependencies for API endpoints
│ │ ├── endpoints # Endpoint implementation
│ │ │ ├── health.py # Health check endpoint
│ │ │ └── items.py # Item endpoints
│ │ └── routes.py # API router
│ ├── core # Core functionality
│ │ └── config.py # Application configuration
│ ├── db # Database
│ │ ├── base.py # Base model imports for Alembic
│ │ ├── base_class.py # Base class for database models
│ │ └── session.py # Database session
│ ├── models # Database models
│ │ └── item.py # Item model
│ ├── schemas # Pydantic schemas
│ │ ├── health.py # Health check schemas
│ │ └── item.py # Item schemas
│ └── services # Business logic
│ └── crud # CRUD operations
│ ├── base.py # Base CRUD class
│ └── item.py # Item CRUD operations
├── main.py # Application entry point
├── migrations # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── README # Alembic README
│ ├── script.py.mako # Alembic script template
│ └── versions # Migration versions
│ └── 20231230_000000_create_items_table.py # Initial migration
└── requirements.txt # Dependencies
Development
Linting
This project uses Ruff for linting:
ruff check .
To automatically fix issues:
ruff check --fix .
Database Migrations
To create a new migration:
alembic revision --autogenerate -m "Description of changes"
To apply migrations:
alembic upgrade head
License
This project is licensed under the MIT License - see the LICENSE file for details.
Description
Languages
Python
97.1%
Mako
2.9%