Index | Feature | HTTP Method | Route | Note |
---|---|---|---|---|
1 | 使用者可以撰寫 tweet | POST | POST /api/tweets | need authentication |
2 | 使用者可以看到所有 tweet | GET | GET /api/tweets | need authentication |
3 | 使用者可以看到特定一則 tweet | GET | GET /api/tweets/:tweet_id | need authentication |
HTTP Method : POST
Request Parameters:No
Request Body :撰寫 tweet 的表單內的資料
Request Name | Type | Required | Example | |
---|---|---|---|---|
推文內容 | description | TEXT | True | Elephants can smell water sources up to 19.2 km away. How cool is that! |
後端收到的格式範例如下
{
"description": "8b8b8b8b8b8b8b8bbooloo"
}
Success Response:
// 成功新增一筆 tweet
Status Code: 200
{
"status": "success"
}
Failure Response:
// current user's role 不是 user
Satus Code: 403
{
"status": "error",
"message": "account not exist"
}
// server 沒收到使用者的 tweet 內容
// 或 tweet 內容空白(全部都打空白鍵也會視為空白 tweet)
Status Code: 500
{
"status": "error",
"message": "Error: Target tweet description is required."
}
// tweet 字數超過 140 字
Status Code: 500
{
"status": "error",
"message": "Error: Characters length of tweet should be less than 140."
}
HTTP Method : GET
Request Parameters:No
Request Body :No
Success Response:
Status Code: 200
[
{
"id": 216,
"description": "Elephants can smell water sources up to 19.2 km away. How cool is that!",
"createdAt": "2022-08-03T05:39:30.000Z",
"user": {
"id": 13,
"account": "user1",
"name": "user1",
"avatar": "<https://loremflickr.com/320/240/paris,girl/all>"
},
"isLiked": false,
"likesCounts": 0,
"repliesCounts": 0
},
{
"id": 215,
"description": "Elephants can smell water sources up to 19.2 km away. How cool is that!",
"createdAt": "2022-08-02T14:42:47.000Z",
"user": {
"id": 13,
"account": "user1",
"name": "user1",
"avatar": "<https://loremflickr.com/320/240/paris,girl/all>"
},
"isLiked": true,
"likesCounts": 1,
"repliesCounts": 0
},
{
"id": 214,
"description": "8b8b8b8b8b8b8b8bbooloo8b8b8b8b8b8b8b8bbooloo8b8b8b8b8b8b8b8bbooloo8b8b8b8b8b8b8b8bbooloo",
"createdAt": "2022-08-02T14:40:39.000Z",
"user": {
"id": 13,
"account": "user1",
"name": "user1",
"avatar": "<https://loremflickr.com/320/240/paris,girl/all>"
},
"isLiked": false,
"likesCounts": 0,
"repliesCounts": 0
},
....
]
Failure Response:
// current user's role 不是 user
Satus Code: 403
{
"status": "error",
"message": "account not exist"
}
// 資料庫內沒有任何一則 tweet
Status Code: 500
{
"status": "error",
"message": "Error: Not any tweet has been post!"
}
HTTP Method : GET
Request Parameters:
Request Name | Type | Required | Example | |
---|---|---|---|---|
推文 id | tweet_id | INTEGER | True | 20 |
Request Body :No