RESTful web requests and user activity tracking websites
Asked Answered
S

3

8

Someone asked me this question a couple of days ago and I didn't have an answer:

As HTTP is a stateless protocol. When we open www.google.com, can it be called a REST call?

What I think:

When we make a search on google.com all info is passed through cookie and URL parameters. It looks like a stateless request. But the search results are not independent of user's past request. Search results are specific to user interest and behavior. Now, it doesn't look like a stateless request.

I know this is an old question and I have read many SO answers like Why HTTP is a stateless protocol? but I am still not able to understand what happens when user activity is tracked like on google or Amazon(recommendations based on past purchases) or any other user activity based recommendation websites.

Is it RESTful or is it RESTless?

What if I want to create a web app in which I use REST architecture and still provide user-specific responses?

Safelight answered 8/11, 2016 at 5:12 Comment(0)
U
7

HTTP is stateless, however the Google Application Layer is not. The specific Cookies and their meaning is part of the Application Layer.

Consider the same with TCP/IP. IP is a stateless protocol, but TCP isn't. The existence of state in TCP embedded in IP packets does not mean that IP protocol itself has a state.

So does that make it a REST call? No.

Although HTTP is stateless & I would suspect that www.google.com when requested with cookies disabled, the results would be the same for each request, making it almost stateless (Google still probably tracks IP to limit request frequency).

But the Application Layer is not stateless. One of the principles of REST is that the system does not retain state data about about the client between requests for the purpose of modifying the responses. In the case of Google, that clearly is not happening.

Unfruitful answered 16/11, 2016 at 4:52 Comment(0)
C
4

It seems that the meaning of "stateless" is being (hypothetically) taken beyond its practical expression.

Consider a web system with no DB at all. You call a (RESTful) API, you always get the exactly the same results. This is perfectly stateless... But this is perfectly not a real system, either.

A real system, in practically every implementation, holds data. Moreover, that data is the "resources" that RESTful API allows us to access. Of course, data changes, due to API calls as well. So, if you get a resource's value, change its value, and then get its value again, you will get a different value than the first read; however, this clearly does not say that the reads themselves were not stateless. They are stateless in the sense that they represent the very same action (or, more exact, resource) for each call. Change has to be manually done, using another RESTful API, to change the resource value, that will then be reflected in the next call.

However, what will be the case if we have a resource that changes without a manual, standard API verb? For example, suppose that we have a resource that counts the number of times some other resource was accessed. Or some other resource that is being populated from some other third party data. Clearly, this is still a stateless protocol.

Moreover, in some sense, almost any system -- say, any system that includes an authentication mechanism -- responds differently for the same API calls, depending, for example, on the user's privileges. And yet, clearly, RESTful systems are not forbidden to authenticate their users...

In short, stateless systems are stateless for the sake of that protocol. If Google tracks the calls so that if I call the same resource in the same session I will get different answers, then it breaks the stateless requirement. But so long as the returned response is different due to application level data, and are not session related, this requirement is not broken.

AFAIK, what Google does is not necessarily related to sessions. If the same user will run the same search under completely identical conditions (e.g., IP, geographical location, OS, browser, etc.), they will get the very same response. If a new identical search will produce different results due to what Google have "learnt" in the last call, it is still stateless, because -- again -- that second call would have produced the very same result if it was done in another session but under identical conditions.

Crustacean answered 16/11, 2016 at 11:18 Comment(0)
O
3

You should probably start from Fielding's comments on cookies in his thesis, and then review Fielding's further thoughts, published on rest-discuss.

My interpretation of Fielding's thoughts, applied to this question: no, it's not REST. The search results change depending on the state of the cookie header in the request, which is to say that the representation of the resource changes depending on the cookie, which is to say that part of the resource's identifier is captured in the cookie header.

Most of the problems with cookies are due to breaking visibility, which impacts caching and the hypertext application engine -- Fielding, 2003

As it happens, caching doesn't seem to be a big priority for Google; the representation returned to be included a cache control private header, which restricts the participation by intermediate components.

Offal answered 8/11, 2016 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.