
- Add email-validator==2.1.0.post1 to requirements.txt - Resolves ImportError when using EmailStr in Pydantic schemas - Required for proper email validation in user endpoints Co-Authored-By: BackendIM <noreply@backendim.com>
REST API Service
A REST API service built with FastAPI, featuring user management, SQLite database, and comprehensive API documentation.
Features
- FastAPI Framework: Modern, fast web framework for building APIs
- SQLite Database: Lightweight, file-based database with SQLAlchemy ORM
- User Management: Complete CRUD operations for user entities
- Database Migrations: Alembic integration for database schema management
- API Documentation: Auto-generated OpenAPI/Swagger documentation
- CORS Support: Cross-Origin Resource Sharing enabled for all origins
- Health Check: Built-in health monitoring endpoint
- Code Quality: Ruff linting and formatting
Project Structure
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── pyproject.toml # Ruff configuration
├── alembic.ini # Alembic configuration
├── alembic/ # Database migrations
│ ├── versions/ # Migration files
│ └── env.py # Alembic environment
└── app/
├── api/
│ └── v1/
│ ├── api.py # API router aggregation
│ └── endpoints/ # API endpoints
│ └── users.py
├── crud/ # Database operations
│ └── user.py
├── db/ # Database configuration
│ ├── base.py # SQLAlchemy base
│ └── session.py # Database session
├── models/ # Database models
│ └── user.py
└── schemas/ # Pydantic schemas
└── user.py
API Endpoints
Base Endpoints
GET /
- Service information and linksGET /health
- Health check endpointGET /docs
- Interactive API documentation (Swagger UI)GET /redoc
- Alternative API documentation (ReDoc)GET /openapi.json
- OpenAPI specification
User Management
GET /api/v1/users/
- List all users (with pagination)GET /api/v1/users/{user_id}
- Get user by IDPOST /api/v1/users/
- Create new userPUT /api/v1/users/{user_id}
- Update userDELETE /api/v1/users/{user_id}
- Delete user
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
Environment Variables
No environment variables are required for basic operation. The application uses SQLite database stored in /app/storage/db/db.sqlite
.
Development
Code Quality
Run linting and formatting:
ruff check --fix .
Database Migrations
Create a new migration:
alembic revision -m "Description of changes"
Apply migrations:
alembic upgrade head
API Usage Examples
Create a User
curl -X POST "http://localhost:8000/api/v1/users/" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"full_name": "John Doe",
"password": "secretpassword"
}'
Get All Users
curl "http://localhost:8000/api/v1/users/"
Health Check
curl "http://localhost:8000/health"
Description
Languages
Python
95.2%
Mako
4.8%