Initial commit

This commit is contained in:
2025-09-08 16:23:54 +08:00
commit 0e1ee0820e
6 changed files with 1304 additions and 0 deletions

85
README.md Normal file
View File

@@ -0,0 +1,85 @@
# Flask API 伺服器
這是一個使用 Flask 和 MySQL 建立的 RESTful API 伺服器,提供使用者資料的 CRUD 操作。
## 功能
- 獲取使用者列表 (支援過濾和分頁)
- 獲取單一使用者資料
- 新增使用者
- 更新使用者資料
- 刪除使用者
## API 端點
### GET /v1/users
獲取使用者列表,支援以下查詢參數:
- `min_age`: 最小年齡過濾
- `max_age`: 最大年齡過濾
- `page`: 頁碼 (預設: 1)
- `limit`: 每頁筆數 (預設: 10)
### GET /v1/users/<id>
獲取指定 ID 的使用者資料
### POST /v1/users
新增使用者,需提供以下 JSON 資料:
```json
{
"name": "使用者名稱",
"email": "使用者信箱",
"age": 使用者年齡
}
```
### PATCH /v1/users/<id>
更新指定 ID 的使用者資料,可提供以下任一欄位:
```json
{
"name": "新名稱",
"email": "新信箱",
"age": 新年齡
}
```
### DELETE /v1/users/<id>
刪除指定 ID 的使用者
## 安裝與執行
1. 安裝相依套件:
```
pip install -r requirements.txt
```
2. 執行伺服器:
```
python app.py
```
伺服器將在 http://127.0.0.1:5000 啟動。
## 回應格式
所有 API 回應皆使用統一格式:
```json
{
"status": "success" 或 "error",
"code": HTTP 狀態碼,
"message": "回應訊息",
"data": 回應資料 (僅在成功時提供)
}
```
## 錯誤處理
錯誤回應格式:
```json
{
"status": "error",
"code": HTTP 錯誤碼,
"message": "錯誤訊息"
}
```