Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
由於我是第一次碰 `typescript` 和 `vuejs`,所以從已經寫比較上手的 `go` 開 始。 定義 API 規格就是確定了 `go` 的部份到底要寫什麼,先訂好 API 可以避免寫後 端程式的時候手賤寫出根本用不到的程式。
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
一個用來練習 `go`/`typescript`/`vuejs` 的小專案,開發歷程詳見 git commit log | ||
|
||
# API 規格 | ||
|
||
- 所有錯誤都會回傳 json 格式錯誤訊息 `"error message"` | ||
- 伺服器錯誤回傳 `500 Internal Server Error` | ||
- 參數錯誤回傳 `400 Bad Request` | ||
- 資料不存在回傳 `404 Not Found` | ||
- 正常回傳 `200 OK` | ||
|
||
回傳值都一定是 json 格式,錯誤訊息是 json string `"error message"`,正常資料則是 json object `{key:value pairs}` | ||
|
||
沒有回傳值的 API 代表它會回傳 `null`,這種狀況只要檢查 http status code 就可以。 | ||
|
||
# 資料結構 - Order | ||
|
||
Order 物件由以下四個欄位組成,通通都是必要欄位 | ||
|
||
- `code`: 三碼英文貨幣代碼,不分大小寫,但伺服器回傳的一定是大寫。 | ||
- `when`: 交易時間的 timestamp。 | ||
- `foreign`: 外幣資產的變動,買入外幣為正,賣出為負。 | ||
- `local`: 本地貨幣資產的變動,買入外幣為負,賣出為正。 | ||
|
||
# API 列表 | ||
|
||
## /api/listall | ||
|
||
一次列出所有交易資料 | ||
|
||
### 回傳值 | ||
|
||
`[Order object, Order object, ...]` | ||
|
||
沒有資料不會回傳 404,而是回傳空陣列。 | ||
|
||
## /api/list | ||
|
||
列出特定外幣的所有交易資料 | ||
|
||
### 參數 | ||
|
||
`{code: "currency code"}` | ||
|
||
`code` 必須是三碼英文,不分大小寫。 | ||
|
||
### 回傳值 | ||
|
||
`[Order, Order, ...]` | ||
|
||
沒有資料不會回傳 404,而是回傳空陣列。 | ||
|
||
## /api/add | ||
|
||
新增一筆交易資料 | ||
|
||
### 參數 | ||
|
||
`Order object` |