
- Set up FastAPI application with CORS support - Implement SQLite database with SQLAlchemy ORM - Create User model with CRUD operations - Add Alembic for database migrations - Include health check and documentation endpoints - Set up proper project structure with organized modules - Add comprehensive README with setup instructions - Configure Ruff for code linting and formatting
89 lines
2.2 KiB
Markdown
89 lines
2.2 KiB
Markdown
# REST API Service
|
|
|
|
A REST API service built with FastAPI and SQLite, providing user management functionality.
|
|
|
|
## Features
|
|
|
|
- FastAPI web framework
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Alembic database migrations
|
|
- CRUD operations for users
|
|
- Health check endpoint
|
|
- Auto-generated OpenAPI documentation
|
|
- CORS support
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── main.py # FastAPI application entry point
|
|
├── requirements.txt # Python dependencies
|
|
├── alembic.ini # Alembic configuration
|
|
├── alembic/ # Database migrations
|
|
│ ├── env.py
|
|
│ ├── script.py.mako
|
|
│ └── versions/
|
|
│ └── 001_initial_migration.py
|
|
└── app/
|
|
├── __init__.py
|
|
├── db/
|
|
│ ├── __init__.py
|
|
│ ├── base.py # SQLAlchemy base
|
|
│ └── session.py # Database session configuration
|
|
├── models/
|
|
│ ├── __init__.py
|
|
│ └── user.py # User model
|
|
├── schemas/
|
|
│ ├── __init__.py
|
|
│ └── user.py # Pydantic schemas
|
|
└── crud/
|
|
├── __init__.py
|
|
└── user.py # CRUD operations
|
|
```
|
|
|
|
## Installation
|
|
|
|
1. Install dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. Start the application:
|
|
```bash
|
|
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /` - Service information
|
|
- `GET /health` - Health check
|
|
- `GET /docs` - OpenAPI documentation
|
|
- `GET /redoc` - Alternative API documentation
|
|
- `POST /users/` - Create a new user
|
|
- `GET /users/` - List all users
|
|
- `GET /users/{user_id}` - Get user by ID
|
|
- `PUT /users/{user_id}` - Update user
|
|
- `DELETE /users/{user_id}` - Delete user
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`.
|
|
|
|
## Environment Variables
|
|
|
|
No environment variables are required for basic operation. The application uses SQLite with default settings.
|
|
|
|
## Development
|
|
|
|
To run the application in development mode:
|
|
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at `http://localhost:8000` with automatic reload on code changes.
|