From e2070659f20ab4dfe87d8aa0cf663deea2ed5615 Mon Sep 17 00:00:00 2001 From: gitee-bot Date: Fri, 1 May 2026 16:19:41 +0000 Subject: [PATCH] Add README.md --- README.en.md | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 README.en.md create mode 100644 README.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..adddfe5 --- /dev/null +++ b/README.en.md @@ -0,0 +1,105 @@ +# FastAPI01 + +A learning example project for FastAPI, featuring RESTful API demonstrations for multiple business modules such as employee management, products, and users. + +## Project Overview + +This is a RESTful API example project built on the FastAPI framework, demonstrating FastAPI's core features including route definition, parameter validation, response models, database integration, and Alembic database migrations. + +## Technology Stack + +- **Web Framework**: FastAPI +- **Database ORM**: SQLAlchemy 2.0 +- **Database Migration**: Alembic +- **Data Validation**: Pydantic +- **Python Version**: Python 3.8+ + +## Project Structure + +``` +├── main.py # FastAPI application entry point +├── alembic.ini # Alembic configuration file +├── alembic/ # Database migration scripts +│ ├── env.py +│ └── versions/ # Migration version files +├── db_test/ # Database models +│ ├── Base.py # Base models and enums +│ ├── Dept.py # Department model +│ ├── Employee.py # Employee model +│ ├── IdCard.py # ID card model +│ ├── User_Role.py # User and role models +│ └── mysql_main.py # Database operation examples +└── router/ # Router modules + ├── emp_router.py # Employee-related endpoints + ├── shop_router.py # Shop-related endpoints + └── user_router.py # User-related endpoints +``` + +## Core Features + +### Database Models + +The project defines the following core data models: + +- **Employee** - Employee information +- **Dept** - Department information +- **IdCard** - ID card information +- **User** / **Role** - User and role information + +### API Endpoints + +#### Basic Endpoints (main.py) + +- `GET /` - Root endpoint +- `GET /hello/{name}` - Greeting endpoint +- `POST /test/{name}` - Test endpoint + +#### Employee Endpoints (emp_router.py) + +- `GET /emp/simple/{emp_id}` - Query employee by ID + +#### Shop Endpoints (shop_router.py) + +- `GET /food` - Get food list +- `GET /bed` - Get bed list + +#### User Endpoints (user_router.py) + +- `GET /list` - User list +- `GET /update` - Update user +- `GET /models/{model_name}` - Model query +- `GET /items/` - Paginated query +- `GET /items/{item_id}` - Detail query +- Examples of various query parameter validations + +## Installation & Configuration + +```bash +# Install dependencies +pip install fastapi uvicorn sqlalchemy alembic pydantic + +# Start the server +uvicorn main:app --reload +``` + +## Usage Examples + +### Request Examples + +```bash +# Get root endpoint +curl http://localhost:8000/ + +# Greeting endpoint +curl http://localhost:8000/hello/John + +# Query employee +curl http://localhost:8000/emp/simple/1 + +# Paginated query +curl http://localhost:8000/items/?skip=0&limit=10 +``` + +## License + +MIT License \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5c973b3 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ + + +# FastAPI01 + +FastAPI 学习示例项目,包含员工管理、商品、用户等多个业务模块的 RESTful API 示范。 + +## 项目简介 + +这是一个基于 FastAPI 框架构建的 RESTful API 示例项目,展示了 FastAPI 的核心功能,包括路由定义、参数验证、响应模型、数据库集成以及 Alembic 数据迁移等。 + +## 技术栈 + +- **Web 框架**: FastAPI +- **数据库 ORM**: SQLAlchemy 2.0 +- **数据库迁移**: Alembic +- **数据验证**: Pydantic +- **Python 版本**: Python 3.8+ + +## 项目结构 + +``` +├── main.py # FastAPI 应用入口 +├── alembic.ini # Alembic 配置文件 +├── alembic/ # 数据库迁移脚本 +│ ├── env.py +│ └── versions/ # 迁移版本文件 +├── db_test/ # 数据库模型 +│ ├── Base.py # 基础模型和枚举 +│ ├── Dept.py # 部门模型 +│ ├── Employee.py # 员工模型 +│ ├── IdCard.py # 身份证模型 +│ ├── User_Role.py # 用户和角色模型 +│ └── mysql_main.py # 数据库操作示例 +└── router/ # 路由模块 + ├── emp_router.py # 员工相关接口 + ├── shop_router.py # 商店相关接口 + └── user_router.py # 用户相关接口 +``` + +## 核心功能 + +### 数据库模型 + +项目定义了以下核心数据模型: + +- **Employee** - 员工信息 +- **Dept** - 部门信息 +- **IdCard** - 身份证信息 +- **User** / **Role** - 用户和角色 + +### API 接口 + +#### 基础接口 (main.py) + +- `GET /` - 根路径 +- `GET /hello/{name}` - 问候接口 +- `POST /test/{name}` - 测试接口 + +#### 员工接口 (emp_router.py) + +- `GET /emp/simple/{emp_id}` - 根据ID查询员工 + +#### 商店接口 (shop_router.py) + +- `GET /food` - 获取食品列表 +- `GET /bed` - 获取床位列表 + +#### 用户接口 (user_router.py) + +- `GET /list` - 用户列表 +- `GET /update` - 用户更新 +- `GET /models/{model_name}` - 模型查询 +- `GET /items/` - 分页查询 +- `GET /items/{item_id}` - 详情查询 +- 多种查询参数验证示例 + +## 安装配置 + +```bash +# 安装依赖 +pip install fastapi uvicorn sqlalchemy alembic pydantic + +# 启动服务 +uvicorn main:app --reload +``` + +## 使用示例 + +### 请求示例 + +```bash +# 获取根路径 +curl http://localhost:8000/ + +# 问候接口 +curl http://localhost:8000/hello/John + +# 查询员工 +curl http://localhost:8000/emp/simple/1 + +# 分页查询 +curl http://localhost:8000/items/?skip=0&limit=10 +``` + +## License + +MIT License \ No newline at end of file -- Gitee