English 中文(简体)
RESTful - Statelessness
  • 时间:2024-12-24

RESTful Web Services - Statelessness


Previous Page Next Page  

As per the REST architecture, a RESTful Web Service should not keep a cpent state on the server. This restriction is called Statelessness. It is the responsibipty of the cpent to pass its context to the server and then the server can store this context to process the cpent s further request. For example, session maintained by server is identified by session identifier passed by the cpent.

RESTful Web Services should adhere to this restriction. We have seen this in the RESTful Web Services - Methods chapter, that the web service methods are not storing any information from the cpent they are invoked from.

Consider the following URL −

https://localhost:8080/UserManagement/rest/UserService/users/1

If you hit the above url using your browser or using a java based cpent or using Postman, result will always be the User XML whose Id is 1 because the server does not store any information about the cpent.

<user> 
   <id>1</id> 
   <name>mahesh</name> 
   <profession>1</profession> 
</user>

Advantages of Statelessness

Following are the benefits of statelessness in RESTful Web Services −

    Web services can treat each method request independently.

    Web services need not maintain the cpent s previous interactions. It simppfies the apppcation design.

    As HTTP is itself a statelessness protocol, RESTful Web Services work seamlessly with the HTTP protocols.

Disadvantages of Statelessness

Following are the disadvantages of statelessness in RESTful Web Services −

    Web services need to get extra information in each request and then interpret to get the cpent s state in case the cpent interactions are to be taken care of.

Advertisements