3.1.2.Introduction to RESTful API

  • Resource

    • Objects, things, entities e.g. 車子的規格, 主人, 價格等狀態, 萬物皆可為資源

    • 由URL來指定, URL即是資源

  • Representation state

    • 因為資源無法透過網路傳輸, 利用網路傳輸的是訊息資源

    • 用戶發出了一個GET請求時, 服務器會去蒐集資源的狀態 (representation state)

  • Representation State Transfer

    • 當服務器為了一個資源發送了一個HTTP請求, 服務器會發送一個文檔做響應

    • e.g. 當有顧客詢價時, 送出query, server所回覆的response便稱為Representation State Transfer

  • Representation of resource

    • 一個資源可以有多重表述 (representation): 服務器可以用XML, JSON或是SQL語句, 都是合法的表述

    • 依照使用者的需求, 存在DB中的resource可以轉換成不同的Data format後呈現

    • RESTful API可以回傳任意格式的response

  • REST API (high level)

    • 如何才被稱作REST API?

    • 不是一種規格, 也不是一種標準

      • HTTP只是一個選擇, 但沒有規定一定要使用

Last updated

Was this helpful?