請求方式說明
FIRST LINE 採用 RESTful 為主設計 API,而使用到的 HTTP 請求方法共有四種方式:
方法 | 描述 |
GET | 請求展示指定資源,即瀏覽資料 |
POST | 用於提交指定資源的實體,即新增資料 |
PUT | 取代指定資源,即更新資料 |
DELETE | 刪除指定資源,即刪除資料 |
請求示範例
下方為使用 POST
請求新增一個客戶的 postman 示意範例
在 Postman 中,建議使用 Body 選擇「raw」並直接輸入JSON。這樣可以避免 Postman 誤將數值轉換為字串,進而防止某些欄位在驗證時出現錯誤。
表頭
表頭的部分有三個,下面逐一解釋:
表頭 | 描述 |
Authorization | 即 token,亦可使用 query string parameter 替代。 |
Content-Type | 確保伺服器接收和回傳都會以 json 形式處理,因此這表頭是必要的。 |
Accept | 為了確保 server 端接收和回傳都會以 json 形式處理,因此這表頭是必要的。 |
其他方法
GET \ DELETE
GET
,DELETE
依此類推,選用對應的 postman 請求方法即可。
PUT
因不支持直接使用 Http PUT 請求。所以,當需要進行PUT請求的時候,請使用POST方法替代,並確保附加_method="put"這一參數。
錯誤代碼
採用標準 HTTP 狀態碼,由 RFC 2616 規範定義的,並得到 RFC 2518、RFC 2817、RFC 2295、RFC 2774 與 RFC 4918 等規範擴充。所有狀態碼被分為五類,狀態碼的第一個數字代表了回應的五種狀態之一。所示的訊息短語是典型的,但是可以提供任何可讀取的替代方案。 除非另有說明,狀態碼是HTTP/1.1標準(RFC 7231)的一部分。
代碼 | 敘述 |
400 | Bad Request - Your request is invalid. |
401 | Unauthorized -- Your API key is wrong. |
403 | Forbidden -- The kitten requested is hidden for administrators only. |
404 | Not Found -- The specified kitten could not be found. |
405 | Method Not Allowed -- You tried to access a kitten with an invalid method. |
406 | Not Acceptable -- You requested a format that isn't json. |
410 | Gone -- The kitten requested has been removed from our servers. |
418 | I'm a teapot. |
419 | Sesstion expired. |
422 | Unprocessable Entity. |
429 | Too Many Requests -- You're requesting too many kittens! Slow down! |
500 | Internal Server Error -- We had a problem with our server. Try again later. |
503 | Service Unavailable |
Last updated