Represents a session containing an ID, expiration time, and content.
Constructors
SessionsessId :: SessionIdUnique identifier for the session.
sessExpiresAt :: UTCTimeExpiration time of the session.
sessContent :: aContent stored in the session.
:: a typeCtrl KGHC 9.14.1 · lts/ghc-9.14.x · 45dd537 · 2026-10-11
Modulescotty-0.30Haskell2010
This module provides session management functionality for Scotty web applications.
{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Web.Scotty.Session
import Control.Monad.IO.Class (liftIO)
main :: IO ()
main = do
-- Create a session jar
sessionJar <- createSessionJar
scotty 3000 $ do
-- Route to create a session
get "/create" $ do
sess <- createUserSession sessionJar "user data"
html $ "Session created with ID: " <> sessId sess
-- Route to read a session
get "/read" $ do
eSession <- getUserSession sessionJar
case eSession of
Left _-> html "No session found or session expired."
Right sess -> html $ "Session content: " <> sessContent sess
Represents a session containing an ID, expiration time, and content.
SessionsessId :: SessionIdUnique identifier for the session.
sessExpiresAt :: UTCTimeExpiration time of the session.
sessContent :: aContent stored in the session.
Type alias for session identifiers.
Type for session storage, a transactional variable containing a map of session IDs to sessions.
Status of a session lookup.
Eq SessionStatusDefined in scotty-0.30 · Web.Scotty.SessionShow SessionStatusDefined in scotty-0.30 · Web.Scotty.SessionCreates a new session jar and starts a background thread to maintain it.
createUserSession Creates a new session for a user, storing the content and setting a cookie.
Creates a new session with a generated ID, sets its expiration, | and adds it to the session jar.
Reads the content of the current user's session.
Reads the content of a session by its ID.
Retrieves the current user's session based on the "sess_id" cookie. | Returns `Left SessionStatus` if the session is expired or does not exist.
Retrieves a session by its ID from the session jar.
Adds or overwrites a new session to the session jar.
Deletes a session by its ID from the session jar.
Continuously removes expired sessions from the session jar.