API 是什麼? RESTful API 又是什麼?

API 是什麼? RESTful API 又是什麼?

API 是什麼? RESTful API 又是什麼?


資料來源: https://medium.com/itsems-frontend/api-%E6%98%AF%E4%BB%80%E9%BA%BC-restful-api-%E5%8F%88%E6%98%AF%E4%BB%80%E9%BA%BC-a001a85ab638


https://hevodata.com/learn/crud-vs-rest/


01.API 是什麼?

    API,全名 Application Programming Interface (應用程式介面),簡單來說,是品牌開發出的一種接口,讓第三方可以額外開發、應用在自身的產品上的系統溝通介面。


02.HTTP 是什麼?

    在 RESTful API 之前,要再理解一下 HTTP,HTTP 是一種協定,全名 Hypertext Transfer Protocol(超文本傳輸協定),網路世界其實就分為客戶端、伺服器端,舉例說,客戶端就是我,伺服器端就是 Yahoo,我要看 Yahoo 的首頁,我就是向 Yahoo 的伺服器端傳送了這個要求,Yahoo 再回應資源給我。為了讓要求和回應統一規範,就有了 HTTP。

    狀態碼又會再分為下幾種:
        2xx = Success(成功)
        3xx = Redirect(重定向)
        4xx = User error(客戶端錯誤)
        5xx = Server error(伺服器端錯誤)


03.RESTful API 是什麼?

    REST,全名 Representational State Transfer( 表現層狀態轉移),他是一種設計風格,RESTful 只是轉為形容詞,像是 peace 和平這名詞,轉成形容詞是 peaceful,RESTful 則形容以此規範設計的 API,稱為 RESTful API。

    一般的 API,可能會是這樣:
        獲得資料GET    /getData
        新增資料POST   /createData
        刪除資料DELETE /deleteData/1


PS.

    對應DB的CRUD ~ 全稱增加(Create,意為「建立」)、刪除(Delete)、查詢(Read,意為「讀取」)、改正(Update,意為「更新」)


    在 HTTP 中,會有很多種 method 做為請求的方法,常用的幾個動作分別為:GET / POST / PUT / DELETE



———


Ultimate CRUD vs REST Guide: Operations Simplified 101

1) HTTP GET: It is used to retrieve resource representation/information with no modifications. As ‘GET’ requests do not change the resource’s state, it is considered a safe method. Additionally, GET APIs are idempotent because they produce the same result, even when multiple identical requests occur. Below are a few cases while using an HTTP GET API:

2) HTTP POST: It is used to create new subresources in an existing directory. Below are the conditions that exist in HTTP POST API:

3) HTTP PUT: It is primarily used to update existing resources. Following are the cases that exist in HTTP PUT API:

4) HTTP DELETE: These functions help mainly delete resources identified by URI. This operation is idempotent. Following are events that may occur:

5) HTTP PATCH: These equests are used to make partial updates on resources. Although PUT requests modify a resource identity, the PATCH method is still the correct choice for partially updating an existing resource. The PATCH method is not universal and may not support all browsers, servers, and web applications. Below is the command to use the PATCH method:


CRUD of the DB

CRUD VS HTTP


RESTful API


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *