Search code examples
reststateful

State in Restful web service


I am new to rest : I am creating a shopping cart like webservice where the user needs to authenticate and add items per user. How to implement this using Rest. What does it mean when they say "REST is stateless" Can I create a session in sqlserver database and return it in response so that client can use it their further call? Does it consider scalable?

I have seen posts on stateful rest service and they have answered saying scalability will be an issue. Also some posts suggest to store the information in database Managing state in RESTful based application But storing the value in database is also some sort of stateful since the client needs to be executed in order and pass some token for further calls. So can i conclude rest is not applicable for shopping cart like applications?


Solution

  • The REST stateless constraint says the client-server communication must be stateless, meaning that each request must contain all information needed to fulfill it. In simpler terms, this means you can't have a server-side session, but it's fine for you to have a client-side session.

    Keep in mind that REST is an architectural style, and that you should follow constraints in order to leverage on the related benefits. If the benefits aren't important for you, it's better to ignore them than to use something that won't be of any good merely to follow the style. The stateless constraint intends to increase visibility, reliability and scalability. Visibility, because the whole request can be understood immediately; reliability because it's easier to recover from server-side failures; and scalability because any server instance can respond any requests. If these aren't important for you, feel free to keep a server-side session if that's easier for you.