Automated Action 993e1df71e Create REST API service with FastAPI and SQLite
- 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
2025-05-19 15:58:21 +00:00

138 lines
3.9 KiB
Markdown

# 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
1. Clone the repository:
```bash
git clone <repository-url>
cd <repository-directory>
```
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Initialize the database:
```bash
alembic upgrade head
```
4. Start the server:
```bash
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 items
- `POST /api/v1/items`: Create a new item
- `GET /api/v1/items/{id}`: Get a specific item
- `PUT /api/v1/items/{id}`: Update a specific item
- `DELETE /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:
```bash
ruff check .
```
To automatically fix issues:
```bash
ruff check --fix .
```
### Database Migrations
To create a new migration:
```bash
alembic revision --autogenerate -m "Description of changes"
```
To apply migrations:
```bash
alembic upgrade head
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.