REST – Do Server-Side Sessions Violate REST Principles?

rest

According to Roy Fielding (one of the principle authors of the HTTP specification) in his seminal thesis Architectural Styles when discussing REST, he mentions:

[E]ach request from client to server must contain all of the information necessary to understand the request, and cannot take advantage of any stored context on the server.

By "stored context" he's referring to application state e.g. what the page number for the next page is vs. resource state e.g. any data store, image etc. – which is arguably the whole point of REST.

Is it fair to say that most attempts at pure rest (hereby defined as an implementation that conforms to the above thesis) must fail due to their reliance on storing session data on the server (persistent or otherwise)?

The concept of a session is common – in particular to Web developers – but is it RESTful according to the above definition?

Best Answer

I would say yes, session state does make a RESTful app non-RESTful. Trivial example, my sister subscribes to the Wall Street Journal. On a regular basis she will be reading something behind the paywall and decide to send a link (via her own email client, not via WSJ) to a friend who does not have a WSJ account. Click, send, fail. Clearly my sister's experience at that URL is different from her friend's.

Related, but not strictly on-topic: I am in the early design phase of a application designed to support significant research efforts on the net (called quests (think: bookmarks on steroids and LSD)) . The owner of the quest wants to share a particular view of his/her data with someone else, but this view requires a combination of UI state (e.g. which visualizations of what data are showing in which panes) along with appropriate permissions to access the UI and the data displayed. There's a lot of stored-state required for the recipient to get the intended view.

My current solution is to store all of the UI/ACL/whatever info necessary for the view in a separate object and return the URL (probably a UUID) for that object. I believe that accessing the view object could be considered RESTful in the sense that everyone in possession of it gets the same info/experience.

Related Topic