tags:

views:

89

answers:

2

I guess this question will sound familiar, but I am yet another programmer baffled by REST.

I have a traditional web application which goes from StateA to StateB and so on If the user goes to (url of) StateB, I want to make sure that he has visited StateA before. Traditionally, I'd do this using session state.

Since session state is not allowed in REST, how do I achieve this?

A: 

It's possible that REST is not the right architecture for this problem.

timdev
It's possible that you are making a claim that you cannot substantiate ;-)
Darrel Miller
+6  A: 

There are 2 REST answers to this, depending on what specifically you are trying to do.

If you are truly trying to manage request-based state (such as when a user is working through a multi-screen wizard or some other navigation-based workflow), then the REST answer is that state should be sent back-and-forth with each request/response (using something like a hidden text field, a query string, or POST data stored in a form). This is an implementation of Martin Fowler's "Client State" design pattern (detailed in full in his book, Patterns of Enterprise Application Architecture; see here for a reference).

If you are, on the other hand, trying to manage some sort of new object on the server--such as a shopping cart--then the REST answer is that you are actually creating a new entity that can be accessed like any other by a direct URL. Whether or not you store this new entity in a database or in application memory (like a traditional Session object) is up to you, but, either way, the new object is less about "state" on the server and more about creating a new entity for the user to interact with.

Ken Taylor
Just one additional point. If you take the "new object on the server" approach then that should be treated as a first class resource and should have an identifying url.
Darrel Miller
Trying to grok REST myself... I'm curious: is "first class" a technical term in this context?
keithjgrant
@keithjgrant I don't know that I would say it is a "technical term" --and it certainly is not specific to REST--but it is a commonly used way of describing any core "object" of a particular technology, programming language, etc., and it connotates that the "first class" object gets special treatement in the technology.
Ken Taylor
@keithjgrant ...continued... For examples: (1) People say that functions are "first class" citizens in JavaScript, because they are more than just subroutines; they are actually "objects" unto themselves (2) F# (a new programming language from Microsoft) is being described as a "first class citizen" of Visual Studio, meaning it is a fully supported programming language in the IDE (3) In Java 1.5 and later, Enums are considered to be "first class citizens" because they are actually supported as a dedicated, specific language construct; prior to Java 1.5, there was no Java "enum" structure.
Ken Taylor