State
To get and set data in your routes, you can use the state
function that is passed as route parameter.
One drawback with the above example is that the "Common" Durable Object will be used for all state
calls. This might present performance issues with heavy loads. In this case, you can specify a different object by setting the first parameter of the state
function.
You can also pass a second string parameter to the state
function in order to use a different instance of the Durable Object. This is useful if you want to access user data by "userId" in the "Users" object, for example: