You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

REST is an acronym for Representational State Transfer. This Wikipedia article offers a good primer on the subject but for those who want to go right to the source, you can read Chapter 5 of Dr. Roy Fielding's dissertation. There are numerous articles and vlogs that cover all types of REST topics. This article will focus on what REST means to the SRP HTTP Framework.

At a simple and high-level, REST is a way of producing and consuming web APIs. In this regard, it is no different from other web API methodologies (generally known as RPC or remote procedure call) such as SOAP or XML-RPC. They all communicate with web servers using URLs and HTTP. Contrary to conventional thinking, REST is not a standard. Rather, REST attempts to describe a philosophy of building web APIs using six different constraints:

  • Client-Server Architecture
  • Statelessness
  • Cacheability
  • Layered System
  • Code on Demand
  • Uniform Interface

Client-Server Architecture is assumed when working with web APIs, so we won't explore this. The Cacheability and Layered System constraints are generally handled through intermediary devices between the client and the server as a way of improving performance and reliability, so we won't explore these either. Finally, Code on Demand is an optional constraint that is only useful in environment where the client and the server are tightly controlled. Therefore we'll skip over this as well.

Statelessness

A stateless system is one where the server is unaware of the state of the client. That is, the server makes no assumptions about what data the client already has or what options are available to the client. In systems where the client state is managed (i.e., a stateful design), this is often handled through session managers, which are server-side systems that track the activity of each client. REST maintains that stateful designs will eventually become over burdened and hinder scalability.

The SRP HTTP Framework does enforce statelessness, but it also does not offer any tools to make the system stateful. Much of this is how the API developer implements the response to a particular request. Developers can move toward statelessness by avoiding, or minimizing database locks, and returning the resource with meta-data that instructs the client how it can request a state change.

Uniform Interface

REST, as it is argued, attempts to use HTTP more faithfully. This is the primary basis for a uniform interface. That is, by adhering to the published HTTP standards, API producers and consumers can better anticipate how to interface with each other. It also provides for greater decoupling, allowing independent evolution between the client and the server.

A key element is that the URL is a reference to a resource on the server rather than a reference to function (or remote procedure) on the server. REST is known for embracing all of the defined HTTP methods so clients can convey a wide variety of intent with the resource. For instance:


APIPurpose

POST /customers

Create a new customer.
GET /customers/{ID}Read a specified customer .
PUT /customers/{ID}Update a specified customer.
DELETE /customers/{ID}Delete a specified customer.

Application and database developers will recognize the above as the basic functions of CRUD. REST is far more than just an alternative way to implement CRUD, but it is a healthy start to understand how REST differs from RPC. One major takeaway is that REST uses four of the well defined HTTP methods to specify action (or intent) and only uses one URL to specify the resource. The {ID} used by some of the APIs technically means there are two URLs, but the resource itself, i.e., customers, is still represented by a singule URL.

RPC methodologies tend to focus on just two HTTP methods, GET and POST, and rely upon the URL or a payload body to specify the action. Here is a very simple RPC example:

APIPurpose

POST /newcustomer

Create a new customer.
GET /readcustomerRead a specified customer .
POST /updatecustomerUpdate a specified customer.
POST /deletecustomerDelete a specified customer.

We will observe that each CRUD action uses a different URL. SOAP will differ from standard RPC in that the URL will tend to be singular but the entire action will be described in the payload.

REST asserts that the advantage of usin

  • No labels