Search code examples
javareststatelessstateful

How restful service identify which user calling which method And how to make restful service as stateful?


As restful service stateless, it don't maintain any interaction of user, so i want to know if multiple user accessing same restful service, then how restful service identify which user interact with which method ? and is it possible to make restful service as stateful ?


Solution

  • Which user:

    By using a shared secret (a line of chars), created on the server, and returned with every next request.

    It's "saved" in a cookie and returned by the client, using either a cookie or a HTTP(S) header.

    Which method:

    This depends on the framework you use. But eventually it comes down to mapping URI's to your methods.

    and is it possible to make restful service as stateful ?

    You can make stateful apps, then they are not restful. A restful app is stateless. That's the definition, so you can make stateful apps, but you can never create a stateful rest-app, as rest is stateless.