---
# System prepended metadata

title: Backend_training v1

---

---
title: Backend_training v1
---

**新增 Todo**
----
  新增一條 Todo 項目

* **URL**

  /todo

* **Method:**

  `POST`
  
*  **URL Params**

   None

* **Data Params**

  ```json
  {
    "title": "title"
  }
  ```

* **Success Response:**

  * **Code:** 201 <br />
    **Content:** `{ "message" : "added todo successfully" }`
 
* **Error Response:**

  * **Code:** 422 UNPROCESSABLE <br />

  OR

  * **Code:** 500 INTERNAL_ERROR <br />

* **Sample Call:**

  ```javascript
    $.ajax({
      url: "/todo",
      dataType: "json",
      type : "POST",
      success : function(r) {
        console.log(r);
      }
    });
  ```


**取得 Todo 列表**
----
  取得 Todo 項目

* **URL**

  /todo

* **Method:**

  `GET`
  
*  **URL Params**

   None

* **Data Params**

   None

* **Success Response:**

  * **Code:** 200 <br />
    **Content:** 
    ```josn
    {
      "todos": [
        {
          "id"
          "title": "test",
          "created_at": "2022-09-13T16:55:27Z",
          "updated_at": "2022-09-13T16:55:27Z",
          "is_done": true,
          "completed_at": "2022-09-14T16:47:52Z"
        }
      ]
    }
    ```
 
* **Error Response:**

  * **Code:** 500 INTERNAL_ERROR <br />
<!--     **Content:** `{ error : "Log in" }` -->

* **Sample Call:**

  ```javascript
    $.ajax({
      url: "/todo",
      dataType: "json",
      type : "GET",
      success : function(r) {
        console.log(r);
      }
    });
  ```
  
**修改 Todo**
----
  修改 Todo 項目

* **URL**

  /todo/:id

* **Method:**

  `PUT`
  
*  **URL Params**

    **Required:**
 
   `id=[integer]`

* **Data Params**

  ```json
  {
    "title": "title"
  }
  ```

* **Success Response:**

  * **Code:** 204 <br />
    **Content:** `{ "message" : "updated todo successfully" }`
 
* **Error Response:**

  * **Code:** 422 UNPROCESSABLE <br />

  OR
  
  * **Code:** 500 INTERNAL_ERROR <br />

* **Sample Call:**

  ```javascript
    $.ajax({
      url: "/todo/1",
      dataType: "json",
      type : "PUT",
      success : function(r) {
        console.log(r);
      }
    });
  ```
  
**刪除 Todo**
----
  刪除 Todo 項目

* **URL**

  /todo/:id

* **Method:**

  `DELETE`
  
*  **URL Params**

    **Required:**
 
   `id=[integer]`

* **Data Params**

    None

* **Success Response:**

  * **Code:** 204 <br />
    **Content:** `{ "message" : "deleted todo successfully" }`
 
* **Error Response:**

  * **Code:** 422 UNPROCESSABLE <br />

  OR

  * **Code:** 500 INTERNAL_ERROR <br />

* **Sample Call:**

  ```javascript
    $.ajax({
      url: "/todo/1",
      dataType: "json",
      type : "DELETE",
      success : function(r) {
        console.log(r);
      }
    });
  ```
  
**切換 Todo done and undone**
----
  刪除 Todo 項目

* **URL**

  /todo/:id/done

* **Method:**

  `POST`
  
*  **URL Params**

    **Required:**
 
   `id=[integer]`

* **Data Params**

    None

* **Success Response:**

  * **Code:** 204 <br />
    **Content:** `{ "message" : "switch is_done successfully" }`
 
* **Error Response:**

  * **Code:** 422 UNPROCESSABLE <br />

  OR

  * **Code:** 500 INTERNAL_ERROR <br />

* **Sample Call:**

  ```javascript
    $.ajax({
      url: "/todo/1/done",
      dataType: "json",
      type : "POST",
      success : function(r) {
        console.log(r);
      }
    });
  ```