Using the Session ΒΆ
The functions and macros to manipulate the session are defined in the
REBLOCKS
/SESSION
package.
Session initialization
When a new user opens the site in the browser, Reblocks does these steps:
Creates a new session object. You can consider it a hash table where some data could be stored.
Generates an unique id and put's this session object to the hash map of all sessions.
Calls the
init
generic function to determine what widget should be shown to the user.Renders the root widget to
HTML
and sends it to the browser.Along with this
HTML
response, sendsSet-Cookie
header to save session id in the browser.
The method you define for init
generic-function should return a root widget.
This widget may include children and render them in it's
reblocks/widget:render
generic-function implementation.
You will find an example of init
in the Quickstart
section.
Storing data
You can store any kind of data in a session.
To set a value, use (SETF GET-VALUE)
function.
For example, you might want to store information about the current user if he logged in:
API
-
[macro]
(env) &body body
Sets dynamic binding for session and env
-
[function]
key &optional default
Get a session value from the currently running webapp.
KEY
is compared usingEQUAL
.
-
[function]
key
Clear the session value for the currently running app.
KEY
is compared usingEQUAL
.
-
[function]
&OPTIONAL (PREFIX "dom")
Generates an
ID
unique accross the session. The generatedID
can be used to createID
s for html elements, widgets, etc.
-
[function]
Checks if session is active and data can be safely retrived or stored.
-
[generic-function]
app
A method for this generic function should be defined to initialize application for a new user session.
It should return a widget which become a root widget.
-
[function]
Returns current session id or signals an error if no current session.
-
[function]
Reset current session.
-
[function]
Deletes current session id for the browser.
On the next
HTTP
request a new session will be created.
- [function] &key (samesite-policy :lax)