A method is a type of function provided by a uniform contract to process resource identifiers. While resource identifiers are generally specific to a REST service, methods are usually not. The uniform contract establishes a set of methods that are expected to be reused by services within a given collection or inventory. Therefore, together with standardizing the resource identifier syntax, the uniform contract standardizes the methods used to process resource identifiers.
Because of the need for methods to be reusable across services, they tend to be highly generic (or uniform). A typical uniform contract will provide a modest set of high-level methods capable of performing basic processing functions. Anything more specific that a service consumer requires of a REST service is expressed in the resource identifier that is processed by the method.
You may have noticed that earlier we referred to methods as the "protocol mechanisms" used to transfer data. This means that when we discuss methods as an element of a uniform contract, we further define (and standardize) the actual protocol technology used to express and transport the generic functions. The most common type of protocol technology used in REST architecture is HTTP.
HTTP provides us with a set of generic methods, such as GET, PUT, POST, DELETE, HEAD and OPTIONS, that are pre-defined in the HTTP specification. The complete protocol interactions in this specification further include a set of response codes, plus syntax for expressing various parameters that can be encoded in HTTP messages.
Let's expand on our previous example by showing how the generated HTTP message expresses the GET statement in the message header, as follows:
GET /customer?ID=C081 HTTP/1.1
In this statement we indicate that by using the GET method, the content associated with a specific customer record (as determined by using the C081 identifier) is requested by the service consumer. (Also indicated by this header statement is the version of HTTP being used.)
Earlier we stated that the uniform contract standardizes the methods that services (within an inventory) use to transfer data. It's important to point out that the uniform contract establishes the available methods services can use. When we design an individual REST service, we can choose which of the available parent uniform contract methods we want our service to support and expose. How this relates to the definition of REST service contracts is discussed shortly.
The use of resource identifiers and methods in REST mirrors the basic mechanics of the World Wide Web. For example, cooking Web sites may provide the ability to search, update and/or view recipes. Instead of exposing these features via a custom API, they offer them as resources that share a common contract (HTTP). A generic service consumer (the Web browser) can access these resources by providing specific resource identifiers (URLs) that are processed by generic methods (supplied by HTTP), as illustrated in Figure 1.
Figure 1 - The Web browser accesses Web resources by providing URLs processed by HTTP methods.