路徑:GET /topics
功能:獲取話題列表,包括熱門和最新話題,支持排序、搜尋及標籤篩選。
請求參數:
sort
(可選):popular
或 newest
,分別對應「熱門」和「最新」排序keyword
(可選):搜尋的關鍵字page
(必填):填入頁數tag
(可選):指定的標籤篩選Request 格式:
### 測試獲取話題列表 API
GET /topics
### 測試獲取話題列表 API (第二頁)
GET /topics?page=2
### 測試獲取話題列表 API (限制結果數量)
GET /topics?limit=5
### 測試獲取話題列表 API (依關鍵字篩選)
GET /topics?keyword=趨勢
### 測試獲取話題列表 API (依標籤篩選)
GET /topics?tags=設計
### 測試獲取話題列表 API (依多個標籤篩選)
GET /topics?tags=設計,資料庫
### 測試獲取話題列表 API (依最新排序)
GET /topics?sort=newest
### 測試獲取話題列表 API (依最舊排序)
GET /topics?sort=oldest
### 測試獲取話題列表 API (依前5筆熱門話題篩選)
GET /topics?sort=popular&limit=5
Response 格式:
{
"status": "success",
"message": "話題列表獲取成功",
"data": [
{
"id": "123456",
"title": "系統設計與最佳實踐",
"author": "匿名用戶",
"author_pic": "<https://randomuser.me/api/portraits/women/46.jpg>",
"description": "這是一個關於系統設計的話題……",
"likes": 45,
"comments": 10,
"bookmarks": 20,
"created_at": "2023-10-05T14:48:00Z",
"tags": ["開發", "系統設計"],
""
},
// 更多話題
]
}
路徑:GET /topics/:id
功能:根據話題 ID 獲取單個話題的詳細內容。
請求參數:
id
(必填):話題的唯一 IDRequest 格式:
GET /topics/5a0bec1f-3d9c-4b28-a9cb-af2b56b3d414
Response 格式:
{
"status": "success",
"message": "話題詳情獲取成功",
"data": {
"id": "5a0bec1f-3d9c-4b28-a9cb-af2b56b3d414",
"title": "區塊鏈技術",
"content": "區塊鏈技術是一種分散式賬本技術,具有去中心化、不可篡改和透明性等特點。區塊鏈在金融、供應鏈管理和數字身份等領域有廣泛應用,未來有望帶來更多創新。",
"author": "Leo",
"likes": 70,
"comments": 30,
"created_at": "2023-10-16T23:15:00+00:00",
"tags": [
"區塊鏈",
"技術"
],
"bookmarks": 6,
"author_pic": "<https://randomuser.me/api/portraits/lego/1.jpg>"
}
}
路徑:GET /topics/:id/comments
功能:獲取指定話題下的所有留言,按時間排序。
請求參數:
id
(必填):話題 IDRequest 格式:
GET /topics/5a0bec1f-3d9c-4b28-a9cb-af2b56b3d414/comments