
- Created main FastAPI application with CORS middleware - Added SQLite database configuration with SQLAlchemy - Implemented Items model with create, read, update, delete operations - Set up Alembic migrations for database schema management - Added comprehensive API endpoints at /api/v1/items/ - Included health check endpoint at /health - Added proper Pydantic schemas for request/response validation - Updated README with complete documentation and usage instructions - Configured Ruff for code linting and formatting
86 lines
2.2 KiB
Markdown
86 lines
2.2 KiB
Markdown
# REST API Service
|
|
|
|
A FastAPI-based REST API service with CRUD operations, SQLite database, and Alembic migrations.
|
|
|
|
## Features
|
|
|
|
- FastAPI framework with automatic API documentation
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- CRUD operations for Items
|
|
- CORS enabled for all origins
|
|
- Health check endpoint
|
|
- Automatic OpenAPI documentation
|
|
|
|
## Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
## Running the Application
|
|
|
|
Start the development server:
|
|
```bash
|
|
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`
|
|
- OpenAPI JSON: `http://localhost:8000/openapi.json`
|
|
|
|
## API Endpoints
|
|
|
|
### Root
|
|
- `GET /` - Service information
|
|
|
|
### Health Check
|
|
- `GET /health` - Health status
|
|
|
|
### Items (CRUD)
|
|
- `POST /api/v1/items/` - Create a new item
|
|
- `GET /api/v1/items/` - List all items (with pagination)
|
|
- `GET /api/v1/items/{item_id}` - Get specific item
|
|
- `PUT /api/v1/items/{item_id}` - Update specific item
|
|
- `DELETE /api/v1/items/{item_id}` - Delete specific item
|
|
|
|
## Database
|
|
|
|
The application uses SQLite with the database file stored at `/app/storage/db/db.sqlite`.
|
|
|
|
### Migrations
|
|
|
|
Database migrations are managed with Alembic. The migration files are in the `alembic/versions/` directory.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── alembic/ # Database migrations
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions/
|
|
│ └── 001_create_items_table.py
|
|
└── app/
|
|
├── api/ # API routes
|
|
│ └── items.py
|
|
├── db/ # Database configuration
|
|
│ ├── base.py
|
|
│ └── session.py
|
|
├── models/ # SQLAlchemy models
|
|
│ └── item.py
|
|
└── schemas/ # Pydantic schemas
|
|
└── item.py
|
|
```
|
|
|
|
## Environment Variables
|
|
|
|
No environment variables are required for basic operation. The application uses SQLite with a file-based database.
|