Skip to search.
rest-discuss · REST Discussion Mailing List

Group Information

  • Members: 1401
  • Category: Protocols
  • Founded: Nov 13, 2001
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

  Messages Help
Advanced
Re: Meaning of stateless (was: Avoiding re-POSTS)   Message List  
Reply Message #5997 of 18829 |
Re: [rest-discuss] Re: Meaning of stateless

Hi John,

On Apr 17, 2006, at 9:37 PM, John Elliot wrote:

> c) A user who arrives at a web-site will initially be
> 'anonymous', yet
> their very first request flags the beginning of a session. The very
> first thing they do might be to 'add item to shopping basket', and the
> very next thing they do 'login'. 'Shopping basket' is an application
> layer function, and it is perfectly reasonable for a server to
> maintain
> this state and associate it with a 'session'. Unfortunately, not all
> 'anonymous' users can share the same shopping basket, and the
> transition
> from 'anonymous' to 'joe' must migrate the shopping basket. The
> shopping
> basket isn't associated with the 'user', it's associated with the
> 'session'.
>
Another way to do the anonymous shopping cart is to give it a unique
URI. When a guest goes to add an initial item to his or her shopping
cart, the server stores it not in the session, but in a set of
shopping cart snapshots, each of which has a unique ID. It then
redirects the client to a URI that includes that shopping cart
snapshot ID with one item in it. If they add another item, then the
server creates another shopping cart snapshot with two items in it
(which has a new ID), and redirects the client to a new URI with the
second ID. The client could log in at that point, even using HTTP
auth. Now we know this is Joe, and the next thing Joe does is add a
third item to his shopping cart. The server creates a third shopping
cart snapshot, and redirects the client to a URI that includes the
unique ID of the third snapshot. In the third snapshot, the server
associates Joe's user ID with the shopping cart, so only he and
admins can look at it.

Any user could look at the shopping cart with one or two items in it,
because it was created by anonymous (before Joe logged in) but if you
use an opaque, hard-to-guess token for the ID, then it would be
highly unlikely that anyone will accidentally go there even if they
are trying. And even if they did go there, all they would know is
someone put in these two items. If they added a third item to
shopping cart, they would essentially bifurcate the shopping cart.
They would get a new shopping cart snapshot with a new ID that would
be included in the URI to which they get redirected.

To me the biggest lesson I learned from reading about REST is that I
don't need session state with HTTP. I can model everything as
resources with unique URIs, some of which require authentication and
authorization. The kind of session I do want is an authentication
session, which simply means the user doesn't have to provide
credentials to the client each time they make an HTTP request. The
user can provide credentials once and then be automatically
authenticated each subsequent request during their authentication
session. Cookies with a fallback on URL rewriting seem to work just
fine for holding this authentication token/session ID. You can even
have the same user working with two different instances of the
application from one client this way. I.e., Joe could actually be
adding different items to two different shopping carts at the same
time from the same browser.

> If you know the 'object' and the 'subject' of a request, then along
> with
> a single verb you have all of the information necessary to create the
> context in which to generate an appropriate response.
>
Well, there are other possibilities. If a user has landed on one of
our sites after searching for "rest relaxation," I want to highlight
those terms in the page. So I need to look at the referrer header. If
they indicate via their accept language headers that they speak
French, and they've requested an English version of an article for
which I have a French translation, I want to add in a prominent link
to the French version into the English page I send back. I want to
also try and detect requests that are coming from a device with a
small screen, and include a prominent link to a mobile version of the
content.

(The following snippet is from your follow-up email.)

> The only thing I'm trying to point out here is that 'session id'
> should
> not be in the URL, but it needs to be there. It should be a
> transparent
> part of the universal uniform interface, and it should be able to
> stand
> as the 'subject' of a request.
>
> If this happens, then we can move toward using the 'subject' *and* the
> 'object' of the request to key a cache of what are otherwise
> non-cacheable responses to HTTP GET.
>
I don't believe this either necessary or desirable. The reason it
isn't necessary is that you can use ETags to identify different
representations, including personalized representations, of the same
resource to caches. The reason it isn't desirable is both because
many sessions can share the same representations, and because I may
want to send multiple representations for the same URI and subject
based on other information in the request (such as referrer or accept-
language). By using ETags, which already exists in HTTP 1.1, I can
effectively identify and cache each representation. The fewer
representations you have, the more caching can help with scalability,
and that mechanism will always be more flexible. At the extreme case,
if you really have a different representation for each session, then
you can include the session ID in the ETag. But most of the time what
you probably really have in that case is a different representation
per user, not per session, so you could include a user ID in the
ETag. But to the extent possible it is better to try and minimize the
number of resources for which there are so many representations,
because the fewer the representations the more scalability benefit
you get from HTTP caching.

For example, I do want to say, "Welcome, John" on the top of every
page once you've signed in. But I'm currently planning on attempting
to have only two representations of each page, one for signed in
users and one for anonymous. The signed in representation will have
some JavaScript that grabs the Welcome greeting and insert it
dynamically on the page. If a client doesn't have JavaScript enabled,
then they still see they are signed in, because that's one of the two
representations sent from the server, but they won't see their name
in a welcome message. To me that's a graceful degradation for non-
JavaScript clients that I'm willing to accept in exchange for
improved cache effectiveness. (The signed in/anonymous
representations only work for clients with cookies enabled. Otherwise
I have to fall back to URL rewriting, where the caching will be less
effective, because I'll have a different URI per resource per session.)

I'm going to try to take the same kind of JavaScript approach with
search keyword highlighting and links to translations, but I may just
send those variations as representations from the server if
JavaScript turns out to be problematic for those use cases. One
attitude I've heard on this list is that if it isn't cacheable it
isn't scalable. To me, caching is one tool in the scalability
toolbox, but not the only one. Another example is using URL-rewriting
if cookies aren't enabled on the client. Yes, this doesn't make as
effective use of caching as cookies or even HTTP auth could, but if
it allows 5% more users to use the site effectively, then it is
useful. Maybe because of the less effective caching on that 5% you
need to add one more node to your server cluster.

In summary, I think ETags provide a very flexible solution to caching
multiple representations of the same resource, and that using a
different URI for each bit of new or changed state resulting from
each HTTP request, you don't need session state. One thing I don't
understand yet is why everyone says cookies are so evil. Is it really
cookies or how they are used that is evil? I can see how having
session state, which can be identified via a cookie, can degrade
caching effectiveness and break the back button. I can also see
privacy problems with persistent cookies. But from every REST-
proponent's disdain for cookies, I feel I must be missing something.
What is really wrong with cookies?

Bill
----
Bill Venners
Editor-in-Chief
Artima Developer
http://www.artima.com




Tue Apr 18, 2006 7:32 pm

billvenners
Offline Offline
Send Email Send Email

Message #5997 of 18829 |
Expand Messages Author Sort by Date

... Just to be clear, I fully understand and respect that the resource URI is the place to indicate all aspects of the request context which are not the...
John Elliot
jj5v1 Offline Send Email
Apr 18, 2006
5:21 am

Hi John, ... Another way to do the anonymous shopping cart is to give it a unique URI. When a guest goes to add an initial item to his or her shopping cart,...
Bill Venners
billvenners Offline Send Email
Apr 18, 2006
7:32 pm

Hi Bill, ... If you think long and hard about this you'll realise that you're effectively storing a session key (or some aspect of the session) in the URI....
John Elliot
jj5v1 Offline Send Email
Apr 19, 2006
1:12 am

... The point of using REST is scalability. Mainly, caching. If the session has a URI, it can be cached. If the session key is in a cookie, the session...
Lyle Kopnicky
qtseep Offline Send Email
Apr 19, 2006
1:53 am

... No. The concerns of 'caching' and 'bookmarkability' ('bookmarkability' is a word. Promise. ;) are truly independent. The way to solve your caching concerns...
John Elliot
jj5v1 Offline Send Email
Apr 19, 2006
2:15 am

Hi John, ... Well, having one basket per user is a fine design choice, but in that case the user couldn't "interact with two instances of the application," as...
Bill Venners
billvenners Offline Send Email
Apr 19, 2006
3:27 am

... I used sloppy language there. Earlier I'd said that the shopping basket had a one to one mapping with the 'session'. Users can have many sessions....
John Elliot
jj5v1 Offline Send Email
Apr 19, 2006
3:38 am

... You're overstating your case. The main talking point with Bill's approach is creating a new URI for each server-identified state of the basket. That btw,...
Bill de hÓra
bdehora Offline Send Email
Apr 19, 2006
8:32 am

Hi Bill, ... It isn't assigning URIs to representations. It is assigning a URI to each piece of conversational state, each of which by definition becomes a...
Bill Venners
billvenners Offline Send Email
Apr 19, 2006
2:24 pm

... I believe that Tim's objection to the Rails idiom was that the /img.png?20060404 and /img.png?20060419 aren't really distinct resources because only one of...
Jim Ancona
scarhill Offline Send Email
Apr 19, 2006
3:44 pm

Hi Jim, ... That's what I took away from Tim Bray's blog too. The problem that Rails is trying to solve is a real one, which is when you have a resource that...
Bill Venners
billvenners Offline Send Email
Apr 19, 2006
4:05 pm

... You have a different idea of what "breaks the back button" means than I do. Since each URI represents a resource, the back button means "go back to the...
Lyle Kopnicky
qtseep Offline Send Email
Apr 19, 2006
5:37 pm

Hi Lyle, ... I'm only talking about conversational state, not persistent state. But I stand corrected about the shopping carts. I looked around, including at...
Bill Venners
billvenners Offline Send Email
Apr 20, 2006
4:00 am

Hi Bill, ... Thanks for drawing out the distinction. The thing is, if you start to think about what 'conversational state' actually is, it starts to seem like...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
5:19 am

Hi John, ... Sure. Conversational state is state about interactions with the user that span multiple HTTP requests, prior to a point in the conversation where...
Bill Venners
billvenners Offline Send Email
Apr 20, 2006
6:51 am

Hi Bill, ... In fairness, I have to admit I knew you'd say this. I just wanted you to so that I could point out why it's not really distinct from what you ...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
1:50 pm

... Er... entirely opaque, even. :P (That'll learn me for posting having just got back from the pub. :)...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
1:56 pm

Hi John, ... Yes. I'm implementing a web application, and implementation is exactly what I'm talking about. Your original post claimed that HTTP and REST are...
Bill Venners
billvenners Offline Send Email
Apr 20, 2006
7:52 pm

Hi Bill, ... Yep, and there's some pretty heavy duty denial that goes on around the issue. :P I've had all the opportunity I wanted to have made my point on...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
8:39 pm

Hi Bill, ... I shouldn't have said that. That *is* a shopping basket resource. We know that. What's more, it's a resource which represents a specific snapshot...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
8:58 pm

Hi John, ... That's a good question. The primary reason is not the back button problem, but scalability of my particular project, a network of sites, and how...
Bill Venners
billvenners Offline Send Email
Apr 20, 2006
11:59 pm

Hi John, ... Ah, perhaps I finally see what you've been trying to say, and I believe I recently brought up the same issue, though in a different way. If you...
Bill Venners
billvenners Offline Send Email
Apr 20, 2006
11:00 pm

Hi Bill, That was a good chat. :) I think we've got largely to the point where we could say we've reached an understanding. Thanks for the tips on ETags and...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
11:13 pm

... IE's string length is currently the lowest if I recall correctly from last summer when a client ran into this. It's even shorter than lynx as I recall. Nic...
Nic
nferrier_tap... Offline Send Email
Apr 20, 2006
11:17 pm

... Some time back I bumped into a problem with very long URLs in IE6 when dragging the icon from the address bar to the desktop to create a shortcut. So, the...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
11:30 pm

... Bookmarklets are strictly limited in size because of limits in how long a URL in the IE favorites list can be. From...
Lucas Gonze
lucas_gonze Offline Send Email
Apr 20, 2006
11:38 pm

... The only limit I've hit in the last few years was in PHP, a server side framework. I had a huge URL holding up to a couple of thousand fields in the query...
Elliotte Harold
elharo@... Send Email
Apr 24, 2006
6:26 pm

... I had a similar experience with ASP and ASP.NET, though in that case it was IIS being set up by the ISP to get paranoid about long URIs (in case there is...
Jon Hanna
hack_poet Online Now Send Email
Apr 25, 2006
9:36 am

Hi Bill, ... In an earlier message I said that you hadn't pleaded a case for *why* you put 'session state' in a URL. However, your case seems to be to what you...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
2:26 pm

... GET /wizard 302 /wizard/page-1 GET /wizard/page-1 <html><body> <form action="/wizard/page-2" method="GET"> <select id="Community" name="Community"> <option...
John Elliot
jj5v1 Offline Send Email
Apr 20, 2006
4:43 pm
 First  |  |  Next > Last 
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help