ToDo List

API 文件

目錄

/api/task

任務管理

GET取得所有任務資料

POST新增任務

/api/task/[id]

特定任務管理

GET取得單一任務資料

PUT更新任務名稱和描述

PATCH更新任務完成與否

DELETE刪除任務

Request headers

"Content-Type": "application/json; charset=utf-8"

/api/task

任務管理

GET取得所有任務資料

SearchParams

參數名稱類型必要限制
showCompletedstring"all" | "completed" | "uncompleted"
sortBystring"created_at" | "updated_at"
sortOrderstring"desc" | "asc"

預設查詢條件:

  1. showCompleted=all 顯示所有任務
  2. sortBy=created_at 根據創建時間排序
  3. sortOrder=desc 降序排列 (從新到舊)

Response example

{
  status: 200, body: [
    {
      "id": 1,
      "name": "Task 1",
      "description": "Description for task 1",
      "is_completed": false,
      "created_at": "2025-05-11T15:04:20.686Z",
      "updated_at": "2025-05-11T15:04:20.686Z"
    },
  ]
}

{ status: 500, error: "系統發生錯誤,請稍後再試" }

POST新增任務

Request body

參數名稱類型必要限制
namestring最多 10 個字
descriptionstring最多 100 個字

Response example

{
  status: 200, body: {
    "id": 4,
    "name": "Task 4",
    "description": null,
    "is_completed": false,
    "created_at": "2025-07-13T14:11:17.985Z",
    "updated_at": "2025-07-13T14:11:17.985Z"
  }
}

{ status: 400, error: "請輸入任務名稱" }

{ status: 400, error: "任務名稱長度不得超過 10 個字" }

{ status: 400, error: "任務描述長度不得超過 100 個字" }

{ status: 500, error: "系統發生錯誤,請稍後再試" }

/api/task/[id]

特定任務管理

GET取得單一任務資料

Params

參數名稱類型必要限制
idnumber

Response example

{
  status: 200, body: {
    "id": 1,
    "name": "Task 1",
    "description": "Description for task 1",
    "is_completed": false,
    "created_at": "2025-05-11T15:04:20.686Z",
    "updated_at": "2025-05-11T15:04:20.686Z"
  }
}

{ status: 404, error: "任務不存在" }

{ status: 500, error: "系統發生錯誤,請稍後再試" }

PUT更新任務名稱和描述

Params

參數名稱類型必要限制
idnumber

Request body

參數名稱類型必要限制
namestring最多 10 個字
descriptionstring最多 100 個字

Response example

{
  status: 200, body: {
    id: 4,
    name: 'Task 4',
    description: 'Description for task 4',
    is_completed: false,
    created_at: 2025-07-14T15:25:19.282Z,
    updated_at: 2025-07-14T15:26:01.017Z
  }
}

{ status: 400, error: "請輸入任務名稱" }

{ status: 400, error: "任務名稱長度不得超過 10 個字" }

{ status: 400, error: "任務描述長度不得超過 100 個字" }

{ status: 404, error: "任務不存在" }

{ status: 500, error: "系統發生錯誤,請稍後再試" }

PATCH更新任務完成與否

Params

參數名稱類型必要限制
idnumber

Response example

{
  status: 200, body: {
    id: 4,
    name: 'Task 4',
    description: 'Description for task 4',
    is_completed: true,
    created_at: 2025-07-14T15:25:19.282Z,
    updated_at: 2025-07-14T15:26:01.017Z
  }
}

{ status: 404, error: "任務不存在" }

{ status: 500, error: "系統發生錯誤,請稍後再試" }

DELETE刪除任務

Params

參數名稱類型必要限制
idnumber

Response example

{ status: 204, body: null }

{ status: 404, error: "任務不存在" }

{ status: 500, error: "系統發生錯誤,請稍後再試" }