Fielding Dissertation CHAPTER 5 Representational State Transfer (REST)
Fielding Dissertation CHAPTER 5 Representational State Transfer (REST)
CHAPTER 5
Representational State Transfer
(REST)
This chapter introduces and elaborates the Representational State Transfer (REST)
architectural style for distributed hypermedia systems, describing the software
engineering principles guiding REST and the interaction constraints chosen to
retain those principles, while contrasting them to the constraints of other
architectural styles. REST is a hybrid style derived from several of the network-
based architectural styles described in Chapter 3 and combined with additional
constraints that define a uniform connector interface. The software architecture
framework of Chapter 1 is used to define the architectural elements of REST and
examine sample process, connector, and data views of prototypical architectures.
The Null style (Figure 5-1) is simply an empty set of constraints. From an
architectural perspective, the null style describes a system in which there are no
1 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
5.1.2 Client-Server
The first constraints added to our hybrid style are those of the client-server
architectural style (Figure 5-2), described in Section 3.4.1. Separation of concerns
is the principle behind the client-server constraints. By separating the user
interface concerns from the data storage concerns, we improve the portability of
the user interface across multiple platforms and improve scalability by simplifying
the server components. Perhaps most significant to the Web, however, is that the
separation allows the components to evolve independently, thus supporting the
Internet-scale requirement of multiple organizational domains.
5.1.3 Stateless
Like most architectural choices, the stateless constraint reflects a design trade-off.
The disadvantage is that it may decrease network performance by increasing the
2 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
5.1.4 Cache
In order to improve network efficiency, we add cache constraints to form the client-
cache-stateless-server style of Section 3.4.4 (Figure 5-4). Cache constraints require
that the data within a response to a request be implicitly or explicitly labeled as
cacheable or non-cacheable. If a response is cacheable, then a client cache is given
the right to reuse that response data for later, equivalent requests.
The advantage of adding cache constraints is that they have the potential to
partially or completely eliminate some interactions, improving efficiency,
scalability, and user-perceived performance by reducing the average latency of a
series of interactions. The trade-off, however, is that a cache can decrease
reliability if stale data within the cache differs significantly from the data that
would have been obtained had the request been sent directly to the server.
The early Web architecture, as portrayed by the diagram in Figure 5-5 [11], was
defined by the client-cache-stateless-server set of constraints. That is, the design
rationale presented for the Web architecture prior to 1994 focused on stateless
client-server interaction for the exchange of static documents over the Internet.
The protocols for communicating interactions had rudimentary support for non-
shared caches, but did not constrain the interface to a consistent set of semantics
for all resources. Instead, the Web relied on the use of a common client-server
implementation library (CERN libwww) to maintain consistency across Web
applications.
3 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
The central feature that distinguishes the REST architectural style from other
network-based styles is its emphasis on a uniform interface between components
(Figure 5-6). By applying the software engineering principle of generality to the
component interface, the overall system architecture is simplified and the visibility
of interactions is improved. Implementations are decoupled from the services they
provide, which encourages independent evolvability. The trade-off, though, is that a
uniform interface degrades efficiency, since information is transferred in a
standardized form rather than one which is specific to an application's needs. The
REST interface is designed to be efficient for large-grain hypermedia data transfer,
optimizing for the common case of the Web, but resulting in an interface that is not
optimal for other forms of architectural interaction.
4 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
The primary disadvantage of layered systems is that they add overhead and latency
to the processing of data, reducing user-perceived performance [32]. For a
network-based system that supports cache constraints, this can be offset by the
benefits of shared caching at intermediaries. Placing shared caches at the
boundaries of an organizational domain can result in significant performance
benefits [136]. Such layers also allow security policies to be enforced on data
crossing the organizational boundary, as is required by firewalls [79].
5.1.7 Code-On-Demand
The final addition to our constraint set for REST comes from the code-on-demand
5 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
style of Section 3.5.3 (Figure 5-8). REST allows client functionality to be extended
by downloading and executing code in the form of applets or scripts. This simplifies
clients by reducing the number of features required to be pre-implemented.
Allowing features to be downloaded after deployment improves system
extensibility. However, it also reduces visibility, and thus is only an optional
constraint within REST.
The notion of an optional constraint may seem like an oxymoron. However, it does
have a purpose in the architectural design of a system that encompasses multiple
organizational boundaries. It means that the architecture only gains the benefit
(and suffers the disadvantages) of the optional constraints when they are known to
be in effect for some realm of the overall system. For example, if all of the client
software within an organization is known to support Java applets [45], then
services within that organization can be constructed such that they gain the benefit
of enhanced functionality via downloadable Java classes. At the same time,
however, the organization's firewall may prevent the transfer of Java applets from
external sources, and thus to the rest of the Web it will appear as if those clients do
not support code-on-demand. An optional constraint allows us to design an
architecture that supports the desired behavior in the general case, but with the
understanding that it may be disabled within some contexts.
REST consists of a set of architectural constraints chosen for the properties they
induce on candidate architectures. Although each of these constraints can be
considered in isolation, describing them in terms of their derivation from common
architectural styles makes it easier to understand the rationale behind their
selection. Figure 5-9 depicts the derivation of REST's constraints graphically in
terms of the network-based architectural styles examined in Chapter 3.
6 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
Unlike the distributed object style [31], where all data is encapsulated within and
hidden by the processing components, the nature and state of an architecture's
data elements is a key aspect of REST. The rationale for this design can be seen in
the nature of distributed hypermedia. When a link is selected, information needs to
be moved from the location where it is stored to the location where it will be used
by, in most cases, a human reader. This is unlike many other distributed processing
paradigms [6, 50], where it is possible, and usually more efficient, to move the
"processing agent" (e.g., mobile code, stored procedure, search expression, etc.) to
the data rather than move the data to the processor.
Each option has its advantages and disadvantages. Option 1, the traditional client-
server style [31], allows all information about the true nature of the data to remain
hidden within the sender, preventing assumptions from being made about the data
structure and making client implementation easier. However, it also severely
restricts the functionality of the recipient and places most of the processing load on
the sender, leading to scalability problems. Option 2, the mobile object style [50],
provides information hiding while enabling specialized processing of the data via
its unique rendering engine, but limits the functionality of the recipient to what is
anticipated within that engine and may vastly increase the amount of data
7 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
transferred. Option 3 allows the sender to remain simple and scalable while
minimizing the bytes transferred, but loses the advantages of information hiding
and requires that both sender and recipient understand the same data types.
The key abstraction of information in REST is a resource. 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. In other words, any concept that might be the
target of an author's hypertext reference must fit within the definition of a
resource. A resource is a conceptual mapping to a set of entities, not the entity that
corresponds to the mapping at any particular point in time.
8 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
whose value changes over time, whereas a mapping to "the paper published in the
proceedings of conference X" is static. These are two distinct resources, even if
they both map to the same value at some point in time. The distinction is necessary
so that both resources can be identified and referenced independently. A similar
example from software engineering is the separate identification of a version-
controlled source code file when referring to the "latest revision", "revision number
1.2.7", or "revision included with the Orange release."
This abstract definition of a resource enables key features of the Web architecture.
First, it provides generality by encompassing many sources of information without
artificially distinguishing them by type or implementation. Second, it allows late
binding of the reference to a representation, enabling content negotiation to take
place based on characteristics of the request. Finally, it allows an author to
reference the concept rather than some singular representation of that concept,
thus removing the need to change all existing links whenever the representation
changes (assuming the author used the right identifier).
5.2.1.2 Representations
9 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
Control data defines the purpose of a message between components, such as the
action being requested or the meaning of a response. It is also used to
parameterize requests and override the default behavior of some connecting
elements. For example, cache behavior can be modified by control data included in
the request or response message.
Depending on the message control data, a given representation may indicate the
current state of the requested resource, the desired state for the requested
resource, or the value of some other resource, such as a representation of the input
data within a client's query form, or a representation of some error condition for a
response. For example, remote authoring of a resource requires that the author
send a representation to the server, thus establishing a value for that resource that
can be retrieved by later requests. If the value set of a resource at a given time
consists of multiple representations, content negotiation may be used to select the
best representation for inclusion in a given message.
The design of a media type can directly impact the user-perceived performance of a
distributed hypermedia system. Any data that must be received before the
recipient can begin rendering the representation adds to the latency of an
interaction. A data format that places the most important rendering information up
front, such that the initial information can be incrementally rendered while the rest
of the information is being received, results in much better user-perceived
performance than a data format that must be entirely received before rendering
can begin.
For example, a Web browser that can incrementally render a large HTML
document while it is being received provides significantly better user-perceived
performance than one that waits until the entire document is completely received
prior to rendering, even though the network performance is the same. Note that
the rendering ability of a representation can also be impacted by the choice of
content. If the dimensions of dynamically-sized tables and embedded objects must
be determined before they can be rendered, their occurrence within the viewing
area of a hypermedia page will increase its latency.
5.2.2 Connectors
REST uses various connector types, summarized in Table 5-2, to encapsulate the
activities of accessing resources and transferring resource representations. The
connectors present an abstract interface for component communication, enhancing
simplicity by providing a clean separation of concerns and hiding the underlying
implementation of resources and communication mechanisms. The generality of
the interface also enables substitutability: if the users' only access to the system is
via an abstract interface, the implementation can be replaced without impacting
the users. Since a connector manages network communication for a component,
information can be shared across multiple interactions in order to improve
efficiency and responsiveness.
10 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
All REST interactions are stateless. That is, each request contains all of the
information necessary for a connector to understand the request, independent of
any requests that may have preceded it. This restriction accomplishes four
functions: 1) it removes any need for the connectors to retain application state
between requests, thus reducing consumption of physical resources and improving
scalability; 2) it allows interactions to be processed in parallel without requiring
that the processing mechanism understand the interaction semantics; 3) it allows
an intermediary to view and understand a request in isolation, which may be
necessary when services are dynamically rearranged; and, 4) it forces all of the
information that might factor into the reusability of a cached response to be
present in each request.
The primary connector types are client and server. The essential difference
between the two is that a client initiates communication by making a request,
whereas a server listens for connections and responds to requests in order to
supply access to its services. A component may include both client and server
connectors.
A third connector type, the cache connector, can be located on the interface to a
client or server connector in order to save cacheable responses to current
interactions so that they can be reused for later requested interactions. A cache
may be used by a client to avoid repetition of network communication, or by a
server to avoid repeating the process of generating a response, with both cases
serving to reduce interaction latency. A cache is typically implemented within the
address space of the connector that uses it.
Some cache connectors are shared, meaning that its cached responses may be
used in answer to a client other than the one for which the response was originally
obtained. Shared caching can be effective at reducing the impact of "flash crowds"
on the load of a popular server, particularly when the caching is arranged
hierarchically to cover large groups of users, such as those within a company's
intranet, the customers of an Internet service provider, or Universities sharing a
national network backbone. However, shared caching can also lead to errors if the
cached response does not match what would have been obtained by a new request.
11 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
REST attempts to balance the desire for transparency in cache behavior with the
desire for efficient use of the network, rather than assuming that absolute
transparency is always required.
The final form of connector type is a tunnel, which simply relays communication
across a connection boundary, such as a firewall or lower-level network gateway.
The only reason it is modeled as part of REST and not abstracted away as part of
the network infrastructure is that some REST components may dynamically switch
from active component behavior to that of a tunnel. The primary example is an
HTTP proxy that switches to a tunnel in response to a CONNECT method request
[71], thus allowing its client to directly communicate with a remote server using a
different protocol, such as TLS, that doesn't allow proxies. The tunnel disappears
when both ends terminate their communication.
5.2.3 Components
REST components, summarized in Table 5-3, are typed by their roles in an overall
application action.
A user agent uses a client connector to initiate a request and becomes the ultimate
recipient of the response. The most common example is a Web browser, which
provides access to information services and renders service responses according to
the application needs.
12 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
An origin server uses a server connector to govern the namespace for a requested
resource. It is the definitive source for representations of its resources and must be
the ultimate recipient of any request that intends to modify the value of its
resources. Each origin server provides a generic interface to its services as a
resource hierarchy. The resource implementation details are hidden behind the
interface.
Intermediary components act as both a client and a server in order to forward, with
possible translation, requests and responses. A proxy component is an intermediary
selected by a client to provide interface encapsulation of other services, data
translation, performance enhancement, or security protection. A gateway (a.k.a.,
reverse proxy) component is an intermediary imposed by the network or origin
server to provide an interface encapsulation of other services, for data translation,
performance enhancement, or security enforcement. Note that the difference
between a proxy and a gateway is that a client determines when it will use a proxy.
13 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
Since the components are connected dynamically, their arrangement and function
for a particular application action has characteristics similar to a pipe-and-filter
style. Although REST components communicate via bidirectional streams, the
processing of each direction is independent and therefore susceptible to stream
transducers (filters). The generic connector interface allows components to be
placed on the stream based on the properties of each request or response.
14 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
REST concentrates all of the control state into the representations received in
response to interactions. The goal is to improve server scalability by eliminating
any need for the server to maintain an awareness of the client state beyond the
current request. An application's state is therefore defined by its pending requests,
the topology of connected components (some of which may be filtering buffered
data), the active requests on those connectors, the data flow of representations in
response to those requests, and the processing of those representations as they are
received by the user agent.
An interesting observation is that the most efficient network request is one that
15 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
doesn't use the network. In other words, the ability to reuse a cached response
results in a considerable improvement in application performance. Although use of
a cache adds some latency to each individual request due to lookup overhead, the
average request latency is significantly reduced when even a small percentage of
requests result in usable cache hits.
The next control state of an application resides in the representation of the first
requested resource, so obtaining that first representation is a priority. REST
interaction is therefore improved by protocols that "respond first and think later."
In other words, a protocol that requires multiple interactions per user action, in
order to do things like negotiate feature capabilities prior to sending a content
response, will be perceptively slower than a protocol that sends whatever is most
likely to be optimal first and then provides a list of alternatives for the client to
retrieve if the first response is unsatisfactory.
The application state is controlled and stored by the user agent and can be
composed of representations from multiple servers. In addition to freeing the
server from the scalability problems of storing state, this allows the user to directly
manipulate the state (e.g., a Web browser's history), anticipate changes to that
state (e.g., link maps and prefetching of representations), and jump from one
application to another (e.g., bookmarks and URI-entry dialogs).
The model application is therefore an engine that moves from one state to the next
by examining and choosing from among the alternative state transitions in the
current set of representations. Not surprisingly, this exactly matches the user
interface of a hypermedia browser. However, the style does not assume that all
applications are browsers. In fact, the application details are hidden from the
server by the generic connector interface, and thus a user agent could equally be
an automated robot performing information retrieval for an indexing service, a
personal agent looking for data that matches certain criteria, or a maintenance
spider busy patrolling the information for broken references or modified content
[39].
The REST style draws from many preexisting distributed process paradigms [6,
50], communication protocols, and software fields. REST component interactions
are structured in a layered client-server style, but the added constraints of the
generic resource interface create the opportunity for substitutability and
inspection by intermediaries. Requests and responses have the appearance of a
remote invocation style, but REST messages are targeted at a conceptual resource
rather than an implementation identifier.
Several attempts have been made to model the Web architecture as a form of
16 of 17 1/10/23, 11:20
Fielding Dissertation: CHAPTER 5: Representational S... https://www.ics.uci.edu/~fielding/pubs/dissertation/re...
The principled use of the REST style in the Web, with its clear notion of
components, connectors, and representations, relates closely to the C2
architectural style [128]. The C2 style supports the development of distributed,
dynamic applications by focusing on structured use of connectors to obtain
substrate independence. C2 applications rely on asynchronous notification of state
changes and request messages. As with other event-based schemes, C2 is
nominally push-based, though a C2 architecture could operate in REST's pull style
by only emitting a notification upon receipt of a request. However, the C2 style
lacks the intermediary-friendly constraints of REST, such as the generic resource
interface, guaranteed stateless interactions, and intrinsic support for caching.
5.5 Summary
This chapter introduced the Representational State Transfer (REST) architectural
style for distributed hypermedia systems. REST provides a set of architectural
constraints that, when applied as a whole, emphasizes scalability of component
interactions, generality of interfaces, independent deployment of components, and
intermediary components to reduce interaction latency, enforce security, and
encapsulate legacy systems. I described the software engineering principles
guiding REST and the interaction constraints chosen to retain those principles,
while contrasting them to the constraints of other architectural styles.
The next chapter presents an evaluation of the REST architecture through the
experience and lessons learned from applying REST to the design, specification,
and deployment of the modern Web architecture. This work included authoring the
current Internet standards-track specifications of the Hypertext Transfer Protocol
(HTTP/1.1) and Uniform Resource Identifiers (URI), and implementing the
architecture through the libwww-perl client protocol library and Apache HTTP
server.
[Top] [Prev] [Next] © Roy Thomas Fielding, 2000. All [How to reference this
rights reserved. work.]
17 of 17 1/10/23, 11:20