Automated Action b00b44023a Add FastAPI REST API with SQLite database
- 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>
2025-05-15 22:33:58 +00:00

91 lines
2.5 KiB
Markdown

# 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
1. Clone the repository:
```bash
git clone <repository-url>
cd genericrestapiservice
```
2. Create a virtual environment and activate it:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Run migrations:
```bash
alembic upgrade head
```
5. Start 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
## 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 endpoint
- `GET /api/v1/items`: List all items
- `POST /api/v1/items`: Create a new item
- `GET /api/v1/items/{item_id}`: Get a specific item
- `PUT /api/v1/items/{item_id}`: Update a specific item
- `DELETE /api/v1/items/{item_id}`: Delete a specific item