[Swift-d26] - 實戰開發 - TODOList - API 前置資料準備

鐵人賽 Swift Day26:TODOList 準備串接後端 REST API,定義需要的 HTTP 請求(GET/POST/PUT/DELETE)格式與 NSURLSession 前置設定。

接下來是要串 隔壁棚的 API XD

從前幾天的 APP 組成

我們所需要的資料大概會是以下幾種:

  • GET todo list
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
GET http://192.168.1.158:3000/user/kerkerj/todos

return:
[
    {
        "_id": "54441f64d84f1ea412db855c",
        "updated_at": "2014-10-19T20:30:28.797Z",
        "created_at": "2014-10-19T20:30:28.797Z",
        "content": "task11syy",
        "user_id": "kerkerj",
        "__v": 0
    },
    {
        "_id": "54441f6fd84f1ea412db855e",
        "updated_at": "2014-10-19T20:30:39.957Z",
        "created_at": "2014-10-19T20:30:39.957Z",
        "content": "task13",
        "user_id": "kerkerj",
        "__v": 0
    }
]
  • Get a todo task
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
GET http://192.168.1.158:3000/user/kerkerj/todos/54441f64d84f1ea412db855c

return:
{
        "_id": "54441f64d84f1ea412db855c",
        "updated_at": "2014-10-19T20:30:28.797Z",
        "created_at": "2014-10-19T20:30:28.797Z",
        "content": "task11syy",
        "user_id": "kerkerj",
        "__v": 0
}
  • Add a todo task
1
2
3
4
POST http://192.168.1.158:3000/user/kerkerj/todos/
data: {"content": "your data"}

return: the data you sent
  • Update a todo task
1
2
3
4
PUT http://192.168.1.158:3000/user/kerkerj/todos/
data: {"content": "your data"}

return: the data you sent
  • Delete a todo task
1
2
3
4
DELETE http://192.168.1.158:3000/user/kerkerj/todos/54441f64d84f1ea412db855c

return 
{"success": "true"}

從以上資料可以知道

最重要的欄位就是 _id, user_id, content

user_id 我們在 app 中就直接寫死了

所以最重要的就是 content 及 _id

今天先允許我偷懶一下,明天就要開始寫 api utility 給 swift 用

comments powered by Disqus
Powered by Hugo. Theme Stack. All Rights Reserved.