This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Chapter 11: REST: Representational State Transfer
This much space has been devoted to URIs because it’s extremely important to prop-
erly understand and implement resource names.
The HTTP specification provides a number of generic methods (the HEAD, GET, and
POST methods were discussed in Chapter 2), but only five are relevant to this discus-
GET, HEAD, POST, PUT, and DELETE. Table 11-3 recalls the operations from
Chapter 2 and defines the new ones.
Unifying the method vocabulary provides tremendous opportunities for simplifying
interactions. It is precisely because HTTP has few methods that HTTP clients and
servers can grow and be extended independently without confusing each other.
Essentially, what are needed are methods that correspond to the “CRUD” concept:
Create, Retrieve, Update, and Delete. In HTTP they are called
GET, POST, DELETE, and
To get a representation from a resource, a client uses the HTTP method GET. This
operation is idempotent, which means that a client may use the result of a previous
operation instead of repeating it; the state of the server shouldn’t be changed in ways
that are visible to the client.
GET is restricted to a single URL line, which enforces one
of the design principles: everything interesting should be URL-addressable. Wanting
to create a system in which resources aren’t URL-addressable means needing to jus-
tify that decision.
Modifying a resource uses the POST operation. This meaning of POST can be ambigu-
ous. It can mean append, create, remove, or modify a portion of resource, or some-
thing else entirely. This ambiguity leads to a number of misuses. For example, in
violation of one of the REST principles, it can be used for data queries without side
Table 11-3. REST methods
GET Retrieves a resource
HEAD Retrieves representation and resource metadata
POST Inserts, updates, or extends a resource; may change the state of other resources
PUT Creates, updates, or replaces a resource
DELETE Deletes a resource