Rest – What does Representational State mean in REST

restsoapweb services

I have been reading all over the net to get the exact meaning of two words:

REPRESENTATIONAL STATE

I have a doubt. I am misunderstanding these terms. i want to clarify understanding with some one how has good idea about this.

My understanding is that, there is a resource located in the server. SO Rest means that, transferring some representational state of this resource to a client.

if server has a resource x, then if we can make representational state y of resource x, and transferring it over the web is what REST means, is this correct or what is the correct meaning of it. could some one explain me this.

Best Answer

Although REST is stateless, it has state transfer in its name. It's a little bit confusing to everyone.

Stateless

When you open a web page in the browser, you will act as a service consumer and the www server will act as a service provider to serve you with a webpage. If it is a normal connection, the client and the server will both perform a handshake and initiate a session (called a TCP connection).

After that, based on the server's and client's behavior, the state will change to either ESTABLISHED, IDLE, TIMEOUT, etc. But in REST, we are using the HTTP protocol which is a stateless, meaning the server will not store any session information about the client. The client is responsible for sending all of the details required by the server to get serviced, meaning when we invoke the URI http://somedomain:8080/senthil/services/page1 from the server, it has enough details about the client to serve page1 fully.

State Transfer

Using the same example, when you open a web page using some URL to view an image file (RESOURCE) on the server,the www server will show you (the client) the image in some format i.e a REPRESENTATION of the RESOURCE (image file).

During this process, the constant resource state of the server (i.e. the state of the image file which is stored in the server database) will be represented to client in an understandable format i.e. application state of the client. So, the resource state will remain constant in respect to clients, and only the representation of the resource will change, which in turn would change the application state.

Finally, the representation of the resource (how the image is displayed to the client), which implicitly changes the state of both the server and the client is called REST.