I'm thinking about how to explain the definition of a RESTful interface and am wondering if a cached page in Drupal would, purely by definition be considered RESTful: http://en.wikipedia.org/wiki/Representational_state_transfer#Constraints

Obviously if I wanted to setup a truly RESTful interface I would use Services or Fago's RestWS modules.

But by definition if the page is cached in D7 (thus there is no state information) is there a difference in definition between returning an xml or json endpoint and cached html page? Would the fact that there is javascript on the page create a state that would make it by definition not RESTful?

Again this is purely intellectual so thanks for any of your thoughts.


If a page is cached or not is in my opinion completely irrelevant. Page caching is transparent to the user and the content, he doesn't know if it is and once the cache expires, he might get something different on the same page. A page could for example be a view that randomly displays a node. Enabling page caching (and the node only switches e.g. every 5 minutes) doesn't change anything.

RESTful is about having a 1-1 mapping between an URL and a resource (or maybe better: a representation of that resource, e.g. a different format). IMHO, it doesn't matter if..

  • authorization is necessary to have access to that resource (anon vs. authorized users)
  • Only a part of that resource is visible (e.g. someone with additional permissions might see more information)
  • If the displayed information changes, as long as it's the same resource on the same URL (e.g., a node could have an access counter that increases every time you view it.)
  • If there is some sort of caching involved, either page or partial caching.
  • Thanks for the response. You say it doesn't matter between auth and anon users, but wouldn't that break the stateless requirement if Drupal is storing session data. From wikipedia "The client–server communication is further constrained by no client context being stored on the server between requests." – acouch Apr 2 '12 at 2:57
  • 1
    Yes, but that state depends on the Cookie that is sent by the client. The very next sentence there reads "Each request from any client contains all of the information necessary to service the request, and any session state is held in the client. The server can be stateful; this constraint merely requires that server-side state be addressable by URL as a resource.". What I mean is that it possible to have RESTful pages with authentication, it's not ruled out because of that. Of course, most websites where you are authenticated aren't. – Berdir Apr 2 '12 at 7:20

as i see it for point Client–server and Stateless

a logged in user will be using a cookie and break these rules

also Manipulation of resources through these representations (point 2. of Uniform Interface)

again, as fe. only logged in users can manipulate nodes, this rule cannot be applyed

so, in my opinion, only an anonymous cached page can be considered RESTful.

except; there would be a URI allowing user-access, like /u234/gwd8932p/node/32(/edit)

each endpoint is is considered valid, so also X(HTML).

javascript is the Code on demand as long as all content is visible in the X(HTML), and not pulled via AJAX.

but - i may be wrong ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.