95 lines
2.5 KiB
Markdown
95 lines
2.5 KiB
Markdown
# Generic REST API Service
|
|
|
|
A robust REST API service built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- RESTful API endpoints with FastAPI
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic for database migrations
|
|
- CRUD operations for Item resources
|
|
- Health check endpoint
|
|
- Comprehensive API documentation with Swagger UI and ReDoc
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8+
|
|
- pip package manager
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone <repository-url>
|
|
cd genericrestapiservice-p3bojs
|
|
```
|
|
|
|
2. Install the dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run the database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
4. 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
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
.
|
|
├── app/
|
|
│ ├── api/ # API endpoints
|
|
│ │ ├── endpoints/ # Endpoint modules
|
|
│ │ └── api.py # API router definitions
|
|
│ ├── core/ # Core application code
|
|
│ │ └── config.py # Application configuration
|
|
│ ├── db/ # Database setup
|
|
│ │ ├── base.py # Import models for Alembic
|
|
│ │ ├── base_class.py # Base SQLAlchemy class
|
|
│ │ └── session.py # Database session setup
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ └── item.py # Item model
|
|
│ └── schemas/ # Pydantic schemas
|
|
│ └── item.py # Item schemas
|
|
├── migrations/ # Alembic migrations
|
|
│ ├── versions/ # Migration scripts
|
|
│ ├── env.py # Alembic environment
|
|
│ └── script.py.mako # Migration script template
|
|
├── alembic.ini # Alembic configuration
|
|
├── main.py # Main application entry point
|
|
├── requirements.txt # Python dependencies
|
|
└── README.md # Project documentation
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### Items
|
|
|
|
- `GET /api/v1/items` - List all items
|
|
- `POST /api/v1/items` - Create a new item
|
|
- `GET /api/v1/items/{item_id}` - Get an item by ID
|
|
- `PUT /api/v1/items/{item_id}` - Update an item
|
|
- `DELETE /api/v1/items/{item_id}` - Delete an item
|
|
|
|
### Health Check
|
|
|
|
- `GET /api/v1/health` - Check API health
|
|
|
|
## License
|
|
|
|
This project is licensed under the MIT License. |