Representational State Transfer (REST)

Web Architecture and Information Management [./]
Spring 2009 — INFO 190-02 (CCN 42509)

Erik Wilde, UC Berkeley School of Information
2009-05-04

Creative Commons License [http://creativecommons.org/licenses/by/3.0/]

This work is licensed under a CC
Attribution 3.0 Unported License
[http://creativecommons.org/licenses/by/3.0/]

Contents E. Wilde: Representational State Transfer (REST)

Contents

E. Wilde: Representational State Transfer (REST)

(2) Abstract

The Web is built on an architectural style called Representational State Transfer (REST). The main idea of this style is to use a uniform interface for all services, which means that each Web site provides the same service. This idea of a uniform interface is apparent in Web documents (browsers can GET documents by following hyperlinks), but also can be extended to cover machine-oriented Web Services. REST is a style that supports loose coupling and massive scalability, as opposed to more traditional ways of how enterprise computing attempts to integrate all functionality in an attempt to hide distribution.



REST: The Definition

Outline (REST: The Definition)

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
REST: The Definition E. Wilde: Representational State Transfer (REST)

(4) The REST Architectural Style

  1. Resource Identification [Resource Identification (1)]
  2. Uniform Interface [Uniform Interface (1)]
  3. Self-Describing Messages [Self-Describing Messages (1)]
  4. Hypermedia Driving Application State [Hypermedia Driving Application State (1)]
  5. Stateless Interactions [Stateless Interactions (1)]


REST: The Definition E. Wilde: Representational State Transfer (REST)

(5) Resource Identification



REST: The Definition E. Wilde: Representational State Transfer (REST)

(6) Uniform Interface



REST: The Definition E. Wilde: Representational State Transfer (REST)

(7) Self-Describing Messages



REST: The Definition E. Wilde: Representational State Transfer (REST)

(8) Hypermedia Driving Application State



REST: The Definition E. Wilde: Representational State Transfer (REST)

(9) Stateless Interactions



Web Architecture

Outline (Web Architecture)

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
Web Architecture E. Wilde: Representational State Transfer (REST)

(11) What is the Web?



Uniform Resource Identifier (URI)

Outline (Uniform Resource Identifier (URI))

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
Uniform Resource Identifier (URI) E. Wilde: Representational State Transfer (REST)

(13) Identifying Resources on the Web

  • Essential for implementing a Resource Identification [Resource Identification (1)]
  • URIs are human-readable universal identifiers for stuff
    • many identification schemes are not human-readable (binary or hex strings)
    • many RPC-based systems do not have universally identified objects
  • Making every thing a universally unique identified thing is important
    • it removes the necessity to scope non-universal identifiers
    • it allows to talk about all things in exactly the same way


Uniform Resource Identifier (URI) E. Wilde: Representational State Transfer (REST)

(14) URI Schemes

URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
  • URIs in their general case are very simple
    • the scheme identifies how resources are identified
    • the identification may be hierarchical or non-hierarchical
  • Many URI schemes are hierarchical
    • it is then possible to use relative URIs such as in a href="../"
    • the slash character is not just a character, in URIs it has semantics
[…] the URI syntax is a federated and extensible naming system wherein each scheme's specification may further restrict the syntax and semantics of identifiers using that scheme.

Uniform Resource Identifier (URI): Generic Syntax, RFC 3986, January 2005 [http://dret.net/rfc-index/reference/RFC3986]



Uniform Resource Identifier (URI) E. Wilde: Representational State Transfer (REST)

(15) Query Information

  • Query components specify additional information
    • it is non-hierarchical information further identifying the resource
    • in most cases, it can be regarded as input to the resource
  • Query components often influence caching
    • successful GET/HEAD requests may be cached
    • only cache query string URIs when explicitly requested (Expires/Cache-Control)
The query component contains non-hierarchical data that, along with data in the path component […], serves to identify a resource within the scope of the URI's scheme and naming authority […].

Uniform Resource Identifier (URI): Generic Syntax, RFC 3986, January 2005 [http://dret.net/rfc-index/reference/RFC3986]



Uniform Resource Identifier (URI) E. Wilde: Representational State Transfer (REST)

(16) Processing URIs

  • Processing URIs is not as trivial as it may seem
    • escaping and normalization rules are non-trivial
    • many implementations are broken
    • complain about broken implementations
    • even more complicated when processing an Internationalized Resource Identifier (IRI)
  • URIs are not just strings
    • URIs are strings with a considerable set of rules attached to them
    • implementing all these rules is non-trivial
    • implementing all these rules is crucial
    • application development environments provide functions for URI handling


Hypertext Transfer Protocol (HTTP)

Outline (Hypertext Transfer Protocol (HTTP))

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
Hypertext Transfer Protocol (HTTP) E. Wilde: Representational State Transfer (REST)

(18) HTTP Methods

  • Safe methods can be ignored or repeated without side-effects
    • arithmetically safe: 41 × 1 × 1 × 1 × 1 …
    • in practice, without side-effects means without relevant side-effects
  • Idempotent methods can be repeated without side-effects
    • arithmetically idempotent: 41 × 0 × 0 × 0 × 0 …
    • in practice, without side-effects means without relevant side-effects
  • Unsafe and non-idempotent methods should be treated with care
  • HTTP has two main safe methods: GET HEAD
  • HTTP has two main idempotent methods: PUT DELETE
  • HTTP has one main overload method: POST


Hypertext Transfer Protocol (HTTP) E. Wilde: Representational State Transfer (REST)

(19) Cookies

  • Cookies are client site state bound to a domain
    • they are convenient because they work without having to use a representation
    • they are inconvenient because they are not embedded in representations
  • Cookies are managed by the client
    • they are shared across browser tabs
    • they are not shared across browsers used by the same user
    • essentially, the client model of cookies is a bit outdated
  • Two major things to look out for when using cookies:
    1. session IDs are application state (i.e., non-resource state)
    2. cookies break the back button (requests contain a URI/cookie combo)
  • The ideal RESTful cookie is never sent to the server
    • cookies as persistent data storage on the client
    • interactions with the server are only using URIs and representations


Representations

Outline (Representations)

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
Representations E. Wilde: Representational State Transfer (REST)

(21) What is a URI?



Representations E. Wilde: Representational State Transfer (REST)

(22) Extensible Markup Language (XML)



Representations E. Wilde: Representational State Transfer (REST)

(23) Resource Description Framework (RDF)



Representations E. Wilde: Representational State Transfer (REST)

(24) Atom



RESTful shopping

Outline (RESTful shopping)

  1. REST: The Definition [6]
  2. Web Architecture [7]
    1. Uniform Resource Identifier (URI) [4]
    2. Hypertext Transfer Protocol (HTTP) [2]
  3. Representations [4]
  4. RESTful shopping [4]
RESTful shopping E. Wilde: Representational State Transfer (REST)

(26) State Management on the Web



RESTful shopping E. Wilde: Representational State Transfer (REST)

(27) State in the Server Application

State in the Server Application

RESTful shopping E. Wilde: Representational State Transfer (REST)

(28) State as a Resource

State as a Resource

RESTful shopping E. Wilde: Representational State Transfer (REST)

(29) Reusing Resources

Reusing Resources

E. Wilde: Representational State Transfer (REST)

(30) Conclusions



2009-05-04 Web Architecture and Information Management [./]
Spring 2009 — INFO 190-02 (CCN 42509)