Tìm hiểu về API, Rest API, Restful API

Mình đang tìm hiểu về API và gặp các thuật ngữ này, mọi người có thể giúp mình làm rõ sự khác nhau giữa 3 thuật ngữ này, cũng như mối quan hệ giữa chúng với ạ? Cảm ơn mọi người.

REST (Representational state transfer) về cơ bản là “underlying architectural principle of the web”. Theo như định nghĩa của Roy Fielding (founder) thì REST là:

REST is an “architectural style” that basically exploits the existing technology and protocols of the Web.

Nó chính là cách để browser (client) và server “nói chuyện” được với nhau mà bạn (user) không “nghe” thấy, bạn có thể hiểu nôm na là thế.

RESTful dùng để ám chỉ web services áp dụng architecture này. (vì webservice có thể sử dụng SOAP, WSDL…etc). Nó giống như là tính từ (adjective) trong tiếng Anh vậy.

Định nghĩa RESTful “Bản che” (censored):

  1. Use HTTP methods explicitly. (GET, POST, PUT, DELETE…etc)
  2. Be stateless.
  3. Expose directory structure-like URIs.
  4. Transfer XML, JavaScript Object Notation (JSON), or both.

“Bản không che” (uncensored)

  • resources being identified by a persistent identifier: URIs are the ubiquitous choice of identifier these days
  • resources being manipulated using a common set of verbs: HTTP methods are the commonly seen case - the venerable Create, Retrieve, Update, Delete becomes POST, GET, PUT, and DELETE. But REST is not limited to HTTP, it is just the most commonly used transport right now.
  • the actual representation retrieved for a resource is dependent on the request and not the identifier: use Accept headers to control whether you want XML, HTTP, or even a Java Object representing the resource
  • maintaining the state in the object and representing the state in the representation
  • representing the relationships between resources in the representation of the resource: the links between objects are embedded directly in the representation
  • resource representations describe how the representation can be used and under what circumstances it should be discarded/refetched in a consistent manner: usage of HTTP Cache-Control headers

Have fun! :slight_smile:

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?