Cookies
2023-08-04
For my TicTacToe web application, I need to somehow store the user's state in such a way that multiple people can play at once. Counter intuitively, the simplest way to do this is to not store the user's state at all! Not on the server, at least. My web app delegates the storage of state to the user, or more specifically, the user's browser, in the form of browser cookies.
The HTML that my web app sends is always a POST form that sends the updated state to the server,
so if you were to look at an ordered list of the request methods of a user during a game it would look like this:
GET, POST, POST, POST, POST ...
The first GET being the initial request sent by the browser. To
manage cookies, I simply tell the user's browser to SetCookie
on that initial GET request and then in subsequent
requests, update that cookie based on the input of the user. This way the server doesn't keep track
of anything, and it is up to the user to remember the state.