2025-06-02 19:18:33 +00:00

107 lines
3.0 KiB
Markdown

# REST API Service
A REST API service built with FastAPI and SQLite.
## Features
- FastAPI for high-performance API endpoints
- SQLite database for simple data storage
- Alembic for database migrations
- Pydantic for data validation
- CORS middleware configured
- Health check endpoint
- API documentation with OpenAPI
## Project Structure
```
.
├── alembic.ini # Alembic configuration
├── app # Application code
│ ├── api # API endpoints
│ │ ├── v1 # API version 1
│ │ │ ├── api.py # API router
│ │ │ └── endpoints # API endpoint modules
│ │ │ └── items.py # Items endpoints
│ │ └── health.py # Health check endpoint
│ ├── core # Core modules
│ │ └── config.py # Application configuration
│ ├── db # Database code
│ │ └── base.py # Database connection code
│ ├── models # SQLAlchemy models
│ │ └── item.py # Item model
│ └── schemas # Pydantic schemas
│ └── item.py # Item schemas
├── main.py # Application entry point
├── migrations # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── script.py.mako # Alembic script template
│ └── versions # Migration versions
│ └── 01_create_items_table.py # Initial migration
└── requirements.txt # Python dependencies
```
## Installation
1. Clone the repository:
```bash
git clone <repository-url>
cd <repository-directory>
```
2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install dependencies:
```bash
pip install -r requirements.txt
```
4. Configure environment variables:
Create a `.env` file based on `.env.example`.
## Database Migrations
Initialize the database:
```bash
alembic upgrade head
```
## Running the API
Start the API server:
```bash
uvicorn main:app --reload
```
The API will be available at http://localhost:8000.
- API documentation: http://localhost:8000/docs
- ReDoc documentation: http://localhost:8000/redoc
- OpenAPI schema: http://localhost:8000/openapi.json
- Health check: http://localhost:8000/health
## 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 a specific item
- `PUT /api/v1/items/{item_id}`: Update a specific item
- `DELETE /api/v1/items/{item_id}`: Delete a specific item
## Environment Variables
- `APP_NAME`: Application name
- `API_V1_STR`: API v1 path prefix
- `CORS_ORIGINS`: CORS allowed origins