REST = REpresentational State Transfer
The elaboration of REST is a part of Roy Fielding's Dissertation
So, what is REST?
Architectural style for distributed hypermedia systems such as World Wide WebSo, REST is an architectural style. Not identical to HTTP, not an API and it's not just one and only for APIs. It is a set of constraints to build a simplified and decoupled system such as Web.
But we want to create an API in REST style, so we'll use the REST constraints to achieve our goal!
Before move on the architectural constraints, first we should take a quick look at the architectural elements.
Architectural elements: (just a minimal representation)
- Data elements
- "Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on"
- "It is something that is sent back and forth between clients and servers"
- "Never send or receive resources, only their representations"
- "Sequence of bytes, HTML document, archive document, image document"
- Part (it can be the entire) of the resource state
- Uniform interface
- Identification of Resources
- "Resources must have a unique identifier which can be use to retrieve a resource (e.g. URI)"
- Manipulation of Resources through Representations
- "Resources can be updated (or added) by sending representations from the client to the server"
- Self-descriptive messages
- "It means each message contains all the information necessary to complete the task"
- Hypermedia As The Engine Of Application State
- "The ability to navigate resources through hyperlinks/hypermedia is the hallmark of REST"
- Layered system
- A client cannot rely a direct connection to the end server
- There can be intermediary layers between the client and the end server
- An intermediary can be a load-balancer or proxy...
- Separation of concerns
- Improves client portability
- Server can be simpler, more scalable
- "each request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server"
- "the data within a response to a request be implicitly or explicitly labeled as cacheable or non-cacheable"
- Code on demand (optional)
- "server can extend the client functionaility by sending back scripts or code"
- The code is the know-how to process the representation of the given resource
Next time we'll move on the discussion of a RESTful API!