0

I believe this question has been discussed to death.

I was reading up on REST and it says that it has to be stateless.

Yes i do understand there are application states and resource states.

Taking for example a normal web service,

Say if i were to log in from PC A and perform some transactions without logging out.

I log in from PC B and perform another set of transactions. However, at this point it seems that the web server is able to know which set of transactions i performed previously. Does it mean that the server stores all my sessions details?

For some services they do even bring you back to the page that you were previously looking at on PC A. How is this possible if it is supposed to be stateless?

  • Your question is kind of confusing. You mention REST, but then you mention logging in and being taken to a page ... In general, when you're talking web pages, you're not talking REST. – Jim Mischel Oct 14 '15 at 13:11
  • I guess I didn't understand rest properly. I would just like to know how does rest fit into the Internet. And if state is held by client. Why does changing a pc still being able to continue where you left off? – aceminer Oct 14 '15 at 13:12
  • REST is not your application. REST is a means and model of communicating with your application. REST (and HTTP) are stateless, but your application, browser, and client are not stateless. – Kasey Speakman Oct 14 '15 at 16:42
  • @aceminer I found this brief introduction to REST very informative; it has some stuff on the stateless nature of REST. – paul Oct 14 '15 at 18:58
2

Being stateless does not mean that NO information is present on the server, it just means that the request performed by the client contains all the needed information for the server to handle the request.

When you log on to a server, that server can send you a session token so it can persist information across requests. All the server needs is for you to send the token back to the server on every subsequent request and it can associate the token with the information that was persisted. This is indeed the way the HTTP-part of the web works.

Compare this to what FTP does: when you connect, the server sets certain variables for you. For example, it 'knows' what your current working directory is and what file transfer mode (ASCII, Binary...) you will use. Uploading a file to an FTP server does not involve you sending the file, along with what the current directory should be, what the transfer mode is, etc... The server 'knows' this because this information is associated with your session.

As for your changing a PC: when you log into a website, it can log what page you are on as you visit them and persist this to a database. If you explicitly log out this information is removed from the database. As long as you don't do that, logging into the website from another client simply puts you back onto the last page you were: the application identifies you by your username, fetches the last page from the database and shows it to you.

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.