This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
REST Principles
|
241
The first group of principles relates to standardized addressing (URI), which
describes how to address resources. The second group of principles relates to stan-
dard application protocol (HTTP), which describes what operations can be applied
to the resources. Stateless interaction in this context means that each request from
client to server must contain all the information necessary to execute the request,
and can’t take advantage of any stored context on the server. The third group of
principles relates to standard resource representation (HTML, GIF, JPG, XML-based
vocabularies), which describes what data is passed to resources or accepted from
them. Standardization of all these key elements of the REST approach allows for the
achievement of widespread interoperability, and an ability to rapidly and indepen-
dently evolve clients, servers and systems as a whole.
Aesthetics of URI Design
Uniform resource locators (URLs), like uniform resource names (URNs), are a sub-
set of the general class of uniform resource identifiers (URIs). The distinction
between URIs, URLs, URNs, and the rest of resource identifiers is often more con-
fusing than useful.
*
In this chapter, the term “URI” refers to all of them.
URI syntax
Before going into detail about resource modeling, let’s first review and elaborate on
URIs as discussed in Chapter 2. An absolute URI reference consists of three parts: a
scheme,ascheme-specific part, and a fragment identifier. Some schemes are hierarchi-
cal, allowing for both relative and absolute URIs (
http:) and some aren’t, allowing
only absolute URIs (such as
mailto:). For hierarchical namespaces, a scheme-spe-
cific part is broken down into authority, path, and query components. Relative URI
references can be created by omitting the scheme and authority components (they
are implied by the context of the URI reference). These forms of URI reference syn-
tax are summarized as follows:
<scheme>:<scheme-specific-part>#<fragment>
<scheme>://<authority><path>?<query>#<fragment>
<path>?<query>#<fragment>
Resource modeling
The strength and flexibility of REST comes from the pervasive use of URIs. REST is
about exposing resources through URIs, not services through messaging interfaces.
On this view, URIs are acted on by HTTP methods, and the result of those actions is
to transfer representations of some resource from the origin server to the client that
* If you’re interested, the paper “URIs, URLs, and URNs: Clarifications and Recommendations” describes the
relationship among the concepts and the reason for the confusion. Check it out at http://www.w3.org/TR/
2001/NOTE-uri-clarification-20010921/.

Get Programming Web Services with Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.