Representational State Transfer

Representational State Transfer

Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. As such, it is not strictly a method for building what are sometimes called "web services." The terms “representational state transfer” and “REST” were introduced in 2000 in the doctoral dissertation of Roy Fielding, [Chapter 5 of Fielding’s dissertation is [http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm “Representational State Transfer (REST)”] .] one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification. The terms have since come into widespread use in the networking community.

REST strictly refers to a collection of network architecture principles which outline how resources are defined and addressed. The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies. These two meanings can conflict as well as overlap. It is possible to design any large software system in accordance with Fielding’s REST architectural style without using HTTP and without interacting with the World Wide Web. [A tutorial on implementing a REST architecture in pure Java (no HTTP or WWW involved) is available at http://www.theserverside.com/tt/articles/article.tss?track=NL-461&ad=656910USCA&l=ARESTfulCorePart3&asrc=EM_NLN_4355675&uid=2625488] It is also possible to design simple XML+HTTP interfaces which do not conform to REST principles, and instead follow a model of remote procedure call. The difference between the uses of the term “REST” therefore causes some confusion in technical discussions.

Systems which follow Fielding’s REST principles are often referred to as “RESTful”.

Principles

Proponents of REST argue that the Web's scalability and growth are a direct result of a few key design principles:

* Application state and functionality are abstracted into resources
* Every resource is uniquely addressable using a universal syntax for use in hypermedia links
* All resources share a uniform interface for the transfer of state between client and resource, consisting of
** A constrained set of well-defined operations
** A constrained set of content types, optionally supporting code on demand
* A protocol which is:
** Client-server
** Stateless
** Cacheable
** Layered

Fielding describes REST's effect on scalability thus:

REST's central principle: resources

An important concept in REST is the existence of resources (sources of specific information), each of which is referenced with a global identifier (e.g., a URI in HTTP). In order to manipulate these resources, "components" of the network (clients and servers) communicate via a standardized interface (e.g., HTTP) and exchange "representations" of these resources (the actual documents conveying the information). For example, a resource which is a circle may accept and return a representation which specifies a center point and radius, formatted in SVG, but may also accept and return a representation which specifies any three distinct points along the curve as a comma-separated list.

Any number of "connectors" (e.g., clients, servers, caches, tunnels, etc.) can mediate the request, but each does so without “seeing past” its own request (referred to as “layering”, another constraint of REST and a common principle in many other parts of information and networking architecture). Thus an application can interact with a resource by knowing two things: the identifier of the resource, and the action required—it does not need to know whether there are caches, proxies, gateways, firewalls, tunnels, or anything else between it and the server actually holding the information. The application does, however, need to understand the format of the information ("representation") returned, which is typically an HTML, XML or JSON document of some kind, although it may be an image, plain text, or any other content.

Claimed benefits

"Many of the statements below refer to REST in the specific context of Web Services, as opposed to SOAP. REST was originally defined in Fielding’s dissertation in the context of information and media access. Fielding did not originally contrast REST with RPC."

Advocates claim that REST:Fact|date=May 2008
* Provides improved response time and reduced server load due to its support for the caching of representations
* Improves server scalability by reducing the need to maintain session state. This means that different servers can be used to handle different requests in a session
* Requires less client-side software to be written than other approaches, because a single browser can access any application and any resource
* Depends less on vendor software and mechanisms which layer additional messaging frameworks on top of HTTP
* Provides equivalent functionality when compared to alternative approaches to communication
* Does not require a separate resource discovery mechanism, due to the use of hyperlinks in representations
* Provides better long-term compatibility and evolvability characteristics than RPC. This is due to:
** The capability of document types such as HTML to evolve without breaking backwards- or forwards-compatibility
** The ability of resources to add support for new content types as they are defined without dropping or reducing support for older content types.

One benefit that's obvious with regards to web based applications is that a ReSTful implementation allows a user to bookmark specific "queries" (or requests) and allows those to be conveyed to others across e-mail, instant messages, or to be injected into wikis, etc. Thus this "representation" of a path or entry point into an application state becomes highly portable.

One can argue that any sufficiently rich command line interface can be considered "ReSTful" ... in that a fully qualified command line and set of switches/options and arguments can access any accessible application state. A web URL with query string is effectively a sort of command line with arguments.

RESTful example: the World Wide Web

The World Wide Web is the key example of a RESTful design. Much of it conforms to the REST principles. The Web consists of the Hypertext Transfer Protocol (HTTP), content types including the Hypertext Markup Language (HTML), and other Internet technologies such as the Domain Name System (DNS).

HTML can include JavaScript and applets to support code on demand, and has implicit support for hyperlinks.

HTTP has a uniform interface for accessing resources, which consists of URIs, "methods", status codes, headers, and content distinguished by MIME type.

The most important HTTP methods are POST, GET, PUT and DELETE. These are often compared with the CREATE, READ, UPDATE, DELETE (CRUD) operations associated with database technologies: [IETF RFC 2616 “Hypertext Transfer Protocol – HTTP/1.1”, R. Fielding et al., June 1999]

The following table associates several common HTTP verbs with similar database operations, however the meaning of the HTTP verbs do not correspond directly with a single database operation. For example, an HTTP PUT is used to set the value of a resource and may result in either a creation or replacement as needed.

HTTP separates the notions of a web server and a web browser. This allows the implementation of each to vary from the other based on the client-server principle. When used RESTfully, HTTP is stateless. Each message contains all the information necessary to understand the request when combined with state at the resource. As a result, neither the client nor the server needs to remember any communication state between messages. Any state retained by the server must be modeled as a resource.

The statelessness constraint can be violated in HTTP using cookies to maintain sessions. Fielding notes the risks of privacy leaks and security complications which often arise through the use of cookies, and the confusions and bugs which can result from interactions between cookies and the “back” button in a browser.

HTTP provides mechanisms to control caching, and permits a conversation between web browser and web cache to occur using the same mechanisms as between web browser and web server. No layer can access any conversation other than the one it is immediately involved with.

It is important to note that HTML links produce "get" HTTP requests. HTML forms allow "get" and "post" methods (in lower-case). The other HTTP methods mentioned here are not available in HTML 4.01 or XHTML 1.0. [cite web
title = HTML 4.01 Specification: Forms in HTML Documents: The Form Element
publisher = W3C
url = http://www.w3.org/TR/html401/interact/forms.html#h-17.3
accessdate = 2008-03-23
]

REST versus RPC

"The statements below refer to REST in the context of Web Services, specifically as opposed to SOAP. Note that Fielding’s dissertation presents REST in the context of information and media access, not web services. It does not contrast REST to RPC, although it does contrast RPC to HTTP (which is used to illustrate an implementation of REST)."

;REST: Resources—Commands are defined in simple terms: resources to be retrieved, stored / get, set—difficult to do many joins;RPC: Commands—Commands are defined in methods with varying complexity: depending on “standard”—easier (?) to hide complex things behind a method;REST: Nouns—Exchanging resources and concepts;RPC: Verbs—Exchanging methods

A RESTful web application requires a different design approach from an RPC application. An RPC application is exposed as one or more network objects, each with an often unique set of functions which can be invoked. Before a client communicates with the application it must have knowledge of the object identity in order to locate it and must also have knowledge of the object type in order to communicate with it.

RESTful design constrains the aspects of a resource which define its interface (the verbs and content types). This leads to the definition of fewer types on the network than an RPC-based application but more resource identifiers (nouns). REST design seeks to define a set of resources with which clients can interact uniformly, and to provide hyperlinks between resources which clients can navigate without requiring knowledge of the whole resource set. Server-provided forms can also be used in a RESTful environment to describe how clients should construct a URL in order to navigate to a particular resource.

Example

An RPC application might define operations such as the following:

getUser() addUser() removeUser() updateUser() getLocation() addLocation() removeLocation() updateLocation() listUsers() listLocations() findLocation() findUser()

Client code to access this application may look something like this:

exampleAppObject = new ExampleApp('example.com:1234') exampleAppObject.removeUser('001')

With REST, on the other hand, the emphasis is on the diversity of resources, or "nouns"; for example, a REST application might define the following resources

http://example.com/users/ http://example.com/users/{user} (one for each user - where {user} is either the user name or the user id) http://example.com/findUserForm http://example.com/locations/ http://example.com/locations/{location} (one for each location - - where {location} is either the location name or the location id) http://example.com/findLocationForm

Client code to access this application may look something like this:

userResource = new Resource('http://example.com/users/001') userResource.delete()

Each resource has its own identifier noun. Clients start at a single resource such as the user resource which represents themselves, and navigate to location resources and other user resources. Clients work with each resource through standard operations, such as GET to download a copy of the resource’s representation, PUT to paste a changed copy over the top of the original, or DELETE to remove the data or state associated with the resource. POST is sometimes used interchangeably with PUT, but can also be seen as a “paste after” rather than a “paste over” request. POST is generally used for actions with side-effects, such as requesting the creation of a purchase order, or adding some data to a collection.Note how each object has its own URL and can easily be cached, copied, and bookmarked.

Uniform interfaces in REST and RPC

The uniform interface allows clients to access data from a range of resources without special code to deal with each one, so long as it is actually uniform. The content returned from a user resource could be the globally standard and RESTful HTML, a less RESTful industry standard representation such as UserML, or an unRESTful application-specific data format. Which content is returned can be negotiated at request time. The content could even be a combination of these representations: HTML can be marked up with microformats which have general or industry-specific appeal, and these microformats can be extended with application-specific information.

Uniform interfaces reduce the cost of client software by ensuring it is only written once, rather than once per application it has to deal with. Both REST and RPC designs may try to maximise the uniformity of the interface they expose by conforming to industry or global standards. In the RPC model these standards are primarily in the form of standard type definitions and standard choreography. In REST it is primarily the choice of standard content types and verbs which controls uniformity.

Public implementations

It is possible to claim an enormous number of RESTful applications on the Web (just about everything accessible through an HTTP GET request or updateable through HTTP POST). Taken more narrowly, in its sense as an alternative to both Web Services generally and the RPC style specifically, REST can be found in a number of places on the public Web:

* The “blogosphere” — the universe of weblogs — is mostly REST-based, since it involves downloading XML files (in RSS or Atom format) which contain lists of links to other resources;
* The Atom Publishing Protocol for publishing to blogs is considered a canonical [http://tools.ietf.org/wg/atompub/draft-ietf-atompub-protocol/ RESTful protocol] ;
* Various websites and web applications offer REST-like developer interfaces to data (e.g. Flickr or Amazon S3).

Note that WSDL version 2.0 now offers support for binding to all the HTTP request methods (not only GET and POST as in version 1.1). [cite web |url=http://www.w3.org/TR/2007/REC-wsdl20-adjuncts-20070626/#_http_binding_default_rule_method |title=Web Services Description Language (WSDL) Version 2.0 Part 2: Adjuncts]

False or weak forms

Some interfaces referred to as being "RESTful" do not intentionally respect REST’s architectural constraints. REST advocate Mark Baker uses the term "accidentally RESTful" [ [http://www.markbaker.ca/blog/2005/04/14/accidentally-restful/ accidentally RESTful] ] to describe interfaces that partially follow REST's architectural constraints. For example, Flickr's interface can be considered RESTful in its use of standalone GET operations, but it does not attempt to support the full range of a REST interface. Other interfaces that use HTTP to tunnel function calls or which offer a “POX/HTTP” (Plain Old XML over HTTP) endpoint are also sometimes referred to as "REST" interfaces.fact|date=April 2008

Implementation challenges

Implementation is hampered by limited support for HTTP PUT and DELETE in popular development platforms. For example, in the LAMP platform, support for PUT must be added as a module. Web searches offer few examples of how to implement updating database-driven content using PUT. For example, it is nontrivial to create a PHP script to update http://example.com/thing/1 with a PUT message when /thing.php will serve a GET request with XML generated from a database. Most published patterns for updating entities use the POST method.

Outside of the Web

Just as much of the web can be seen as RESTful or nearly RESTful, a number of existing protocols and architectures have RESTful characteristics. Software which may interact with a number of different kinds of objects or devices can do so by virtue of a uniform, agreed interface. Many of these uniform interfaces follow document-oriented REST patterns rather than object-oriented patterns [should expand on and thus clarify this distinction] :

Modbus

Modbus is a protocol which allows memory ranges within PLCs to be addressed. Ranges can be written and read effectively as PUT and GET operations.

JavaBeans

JavaBeans and other systems which perform property-based editing follow the PUT and GET model of the REST architectural style. Rather than write object-specific editor code, the code is written once and can interact with various object types. Resources in this model are defined by the combination of an object identifier and a property name.

SNMP

The SNMP protocol and its object model, which predate the Web, share some characteristics with RESTful systems. A strict verb discipline follows from the protocol's small operator set, and the 'resources' are addressed with a uniform global scheme of Object Identifiers. Most interaction occurs in client-server fashion, and the clients and servers (called managers and agents respectively) can be deployed and evolved independently. Each request-response pair can be understood in isolation.

However, movement through the space of Object identifiers is not assisted by hyperlinks, nor is it considered as traversal through states in a state machine. Rather, the manager uses prior knowledge of the Management Information Bases supported by this particular agent to request or change the information it is interested in. SNMP is focused on providing data about known elements of a device or entity in a LAN or limited-access WAN scope, rather than issues of Internet scaling and links between independently authored content.

Footnotes

References

*Citation
last1=Fielding
first1=Roy T.
last2=Taylor
first2=Richard N.
date=2002-05
year=2002
title=Principled Design of the Modern Web Architecture
url=http://www.ics.uci.edu/~taylor/documents/2002-REST-TOIT.pdf
format=PDF
journal=ACM Transactions on Internet Technology (TOIT)
publisher=Association for Computing Machinery
location=New York
volume=2
issue=2
pages=115–150
doi=10.1145/514183.514185
issn=1533-5399

*Citation|last=Fielding|first=Roy Thomas|year=2000|title=Architectural Styles and the Design of Network-based Software Architectures|version=Doctoral dissertation|publisher=University of California, Irvine|url=http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm|format=HTML

*Citation
last1=Pautasso
first1=Cesare
last2=Zimmermann
first2=Olaf
last3=Leymann
first3=Frank
date=2008-04
month=April
year=2008
title=RESTful Web Services vs. Big Web Services: Making the Right Architectural Decision
url=http://www.jopera.org/docs/publications/2008/restws
format=HTML
journal=17th International World Wide Web Conference (WWW2008)
location=Beijing, China

External links

* [http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm “Architectural Styles and the Design of Network-based Software Architectures”] : Roy Fielding's doctoral dissertation
* [http://rest.blueoxen.net/cgi-bin/wiki.pl?FrontPage RESTwiki] : “descriptions of REST, records of the experiences of REST proponents, and resources to help you apply REST [...] to your software or framework”
* [http://www.infoq.com/articles/rest-introduction "Stefan Tilkov: A Brief Introduction to REST"]
* [http://www.infoq.com/articles/tilkov-rest-doubts "Stefan Tilkov: Addressing REST Doubts"]
* [http://www.infoq.com/articles/rest-anti-patterns "Stefan Tilkov: REST Anti-Patterns"]
* [http://www.xml.com/pub/a/2005/04/06/restful.html “Constructing or Traversing URIs?”] : discusses the constraint on components to use “hypermedia as the engine of application state”.
* [http://duncan-cragg.org/blog/post/getting-data-rest-dialogues/ The REST Dialogues, Part 1: “Getting Data”] : one of nine lessons on applying REST to Web-based business, each lesson in the form of dialog between the author and a fictitious senior technical employee of a company conducting Web-based business.
* [http://wiki.opengarden.org/REST/REST_for_the_Rest_of_Us “REST for the Rest of Us”] : “showcases common REST design patterns that can be put to immediate use”.
* [http://www.viddler.com/explore/MindTouch/videos/28/ “MindTouch: Introduction to REST”] : slides and narration explaining REST.
* [http://bitworking.org/news/201/RESTify-DayTrader “RESTify DayTrader”] : a tour of a day-trading interface in REST style.
* [http://www.xfront.com/REST-Web-Services.html “Building Web Services the REST Way”]
* [http://tomayko.com/writings/rest-to-my-wife "How I Explained REST to my Wife"]
* [http://astoria.mslivelabs.com/ "Microsoft ADO.NET Data Services (formerly Project Codename Astoria) for REST"]
* [http://nicolas-zozol.developpez.com/tutorial/java/rest-jsp-english/ “RESTful Web Services with JSP”] : Tutorial for easy RESTful Web Service with JSP
* [http://acet.rdg.ac.uk/projects/tycho/ Tycho] : a wide-area RESTful P2P distributed registry and asynchronous messaging system.
* [http://rest-client.googlecode.com/ RESTClient] : a tool to execute/test/debug REST webservices and applications.


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Representational state transfer — REST (Representational State Transfer) est une manière de construire une application pour les systèmes distribués comme le World Wide Web. Le terme a été inventé par Roy Fielding en 2000. REST n est pas un protocole ou un format, c est un style d …   Wikipédia en Français

  • Representational State Transfer — Saltar a navegación, búsqueda La Transferencia de Estado Representacional (Representational State Transfer) o REST es una técnica de arquitectura software para sistemas hipermedia distribuidos como la World Wide Web. El término se originó en el… …   Wikipedia Español

  • Representational State Transfer — Dieser Artikel wurde aufgrund von inhaltlichen Mängeln auf der Qualitätssicherungsseite der Redaktion Informatik eingetragen. Dies geschieht, um die Qualität der Artikel aus dem Themengebiet Informatik auf ein akzeptables Niveau zu bringen. Hilf… …   Deutsch Wikipedia

  • Representational State Transfer — REST (Representational State Transfer) est une manière de construire une application pour les systèmes distribués comme le World Wide Web. Le terme a été inventé par Roy Fielding en 2000. REST n’est pas un protocole ou un format, c’est un style… …   Wikipédia en Français

  • Examples of Representational State Transfer — The following are public examples of Representational State Transfer interfaces.Since REST is defined very broadly, it is possible to claim an enormous number of RESTful applications on the Web (just about everything accessible through an HTTP… …   Wikipedia

  • State (disambiguation) — State or The State may refer to:Government* A sovereign political entity ** State ** Unitary state ** Nation state ** State (law), a well defined jurisdiction, with its own set of laws and courts. *State (country subdivision), a non sovereign… …   Wikipedia

  • Hypertext Transfer Protocol — HTTP Persistence · Compression · HTTPS Request methods OPTIONS · GET · HEAD · POST · PUT · DELETE · TRACE · CONNECT Header fields Cookie · ETag · Location · Referer DNT · …   Wikipedia

  • REST — Representational State Transfer REST (Representational State Transfer) est une manière de construire une application pour les systèmes distribués comme le World Wide Web. Le terme a été inventé par Roy Fielding en 2000. REST n est pas un… …   Wikipédia en Français

  • Rest — Representational State Transfer REST (Representational State Transfer) est une manière de construire une application pour les systèmes distribués comme le World Wide Web. Le terme a été inventé par Roy Fielding en 2000. REST n est pas un… …   Wikipédia en Français

  • REST — Representational State Transfer (Academic & Science » Physics) Representational State Transfer (Academic & Science » Physics) Representational State Transfer (Computing » Networking) * Restricted Environmental Stimulation Technique (Academic &… …   Abbreviations dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”