Automated Action cd7c0162fe Create REST API with FastAPI and SQLite
- Implemented project structure with FastAPI framework
- Set up SQLite database with SQLAlchemy ORM
- Created Alembic for database migrations
- Implemented Item model and CRUD operations
- Added health check endpoint
- Added error handling
- Configured API documentation with Swagger UI

generated with BackendIM... (backend.im)
2025-05-13 15:58:51 +00:00

84 lines
2.0 KiB
Markdown

# Generic REST API Service
A RESTful API service built with FastAPI and SQLite, providing standard CRUD operations with a clean architecture.
## Features
- FastAPI framework for high performance
- SQLite database with SQLAlchemy ORM
- Alembic for database migrations
- RESTful API endpoints
- Input validation with Pydantic
- Error handling
- Health check endpoint
- Interactive API documentation with Swagger
## Project Structure
```
├── alembic/ # Database migrations
│ └── versions/ # Migration scripts
├── app/ # Application code
│ ├── api/ # API endpoints
│ │ ├── endpoints/ # Individual API route handlers
│ │ └── routes.py # API router setup
│ ├── database.py # Database connection setup
│ ├── errors.py # Error handling
│ ├── models.py # SQLAlchemy models
│ └── schemas.py # Pydantic schemas
├── main.py # Application entry point
├── alembic.ini # Alembic configuration
└── requirements.txt # Project dependencies
```
## Installation
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```
## Usage
Run the application:
```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
## API Endpoints
### Health Check
- `GET /health` - Check API health status
### Items
- `GET /items` - List all items (with optional filtering)
- `POST /items` - Create a new item
- `GET /items/{item_id}` - Get a specific item
- `PUT /items/{item_id}` - Update an item
- `DELETE /items/{item_id}` - Delete an item
## Database Management
This project uses Alembic for database migrations:
```bash
# Apply migrations
alembic upgrade head
# Create a new migration
alembic revision -m "description"
```
The SQLite database is stored at `/app/storage/db/db.sqlite`.