Session handling in Snap
In this recipe, we will work with session manager data type, SessionManager
in Snap. The HTTP is a connection-less protocol, and the concept of a session has to be built on top of the interaction between client and server. The session is usually represented by some key-value pair that can be persisted across the interactions between a client and the server. In HTTP, this can be done in multiple ways--one of the most popular ways of handling a session is to set the session cookies. The session cookies are retained by the browser for a particular interaction duration.
In this recipe, we will set session cookies through cookie based the session manager in Snap.
How to do it...
- Create a new project,
session-in-snap
, with asimple
stack template:
stack new session-in-snap simple
- Add a dependency on the
snap-core
library in thebuild-depends
subsection of theexecutable
section. Add the other libraries necessary for working with Snap:
executable session-in-snap ...