title: Is That REST API Really RPC? Roy Fielding Seems to Think So
body: <p>A large amount of what I thought I knew about REST is apparently wrong - and I'm not alone. This question has a long lead-in, but it seems to be necessary because the information is a bit scattered. The actual question comes at the end if you're already familiar with this topic.</p>
  
  <p>From the first paragraph of Roy Fielding's <a href="http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven" rel="noreferrer">REST APIs must be hypertext-driven</a>, it's pretty clear he believes his work is being widely misinterpreted:</p>
  
  <blockquote>
    <p>I am getting frustrated by the number of people calling any HTTP-based interface a REST API. Today’s example is the <a href="http://wikis.glassfish.org/socialsite/Wiki.jsp?page=FinalizeRESTAPI" rel="noreferrer">SocialSite REST API</a>. That is RPC. It screams RPC. There is so much coupling on display that it should be given an X rating.</p>
  </blockquote>
  
  <p>Fielding goes on to list several attributes of a REST API. Some of them seem to go against both common practice and common advice on SO and other forums. For example:</p>
  
  <ul>
  <li><p>A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). ...</p></li>
  <li><p>A REST API must not define fixed resource names or hierarchies (an obvious coupling of client and server). ...</p></li>
  <li><p>A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types. ...</p></li>
  </ul>
  
  <p>The idea of "hypertext" plays a central role - much more so than URI structure or what HTTP verbs mean. "Hypertext" is defined in one of the comments:</p>
  
  <blockquote>
    <p>When I [Fielding] say hypertext, I mean the simultaneous presentation of information and controls such that the information becomes the affordance through which the user (or automaton) obtains choices and selects actions. Hypermedia is just an expansion on what text means to include temporal anchors within a media stream; most researchers have dropped the distinction.</p>
    
    <p>Hypertext does not need to be HTML on a browser. Machines can follow links when they understand the data format and relationship types.</p>
  </blockquote>
  
  <p>I'm guessing at this point, but the first two points above seem to suggest that API documentation for a Foo resource that looks like the following leads to tight coupling between client and server and has no place in a RESTful system.</p>
  
  <pre><code>GET   /foos/{id}  # read a Foo
  POST  /foos/{id}  # create a Foo
  PUT   /foos/{id}  # update a Foo
  </code></pre>
  
  <p>Instead, an agent should be forced to discover the URIs for all Foos by, for example, issuing a GET request against /foos. (Those URIs may turn out to follow the pattern above, but that's beside the point.) The response uses a media type that is capable of conveying how to access each item and what can be done with it, giving rise to the third point above. For this reason, API documentation should focus on explaining how to interpret the hypertext contained in the response.</p>
  
  <p>Furthermore, every time a URI to a Foo resource is requested, the response contains all of the information needed for an agent to discover how to proceed by, for example, accessing associated and parent resources through their URIs, or by taking action after the creation/deletion of a resource.</p>
  
  <p>The key to the entire system is that the response consists of hypertext contained in a media type that itself conveys to the agent options for proceeding. It's not unlike the way a browser works for humans.</p>
  
  <p>But this is just my best guess at this particular moment.</p>
  
  <p>Fielding posted a <a href="http://roy.gbiv.com/untangled/2008/specialization" rel="noreferrer">follow-up</a> in which he responded to criticism that his discussion was too abstract, lacking in examples, and jargon-rich:</p>
  
  <blockquote>
    <p>Others will try to decipher what I have written in ways that are more direct or applicable to some practical concern of today. I probably won’t, because I am too busy grappling with the next topic, preparing for a conference, writing another standard, traveling to some distant place, or just doing the little things that let me feel I have I earned my paycheck.</p>
  </blockquote>
  
  <p>So, two simple questions for the REST experts out there with a practical mindset: how do you interpret what Fielding is saying and how do you put it into practice when documenting/implementing REST APIs?</p>
  
  <p><em>Edit: this question is an example of how hard it can be to learn something if you don't have a name for what you're talking about. The name in this case is "Hypermedia as the Engine of Application State" (HATEOAS).</em></p>