wisp_kv_sessions

Types

pub type CurrentSession {
  CurrentSession(
    req: wisp.Request,
    config: session_config.Config,
  )
}

Constructors

  • CurrentSession(req: wisp.Request, config: session_config.Config)
pub type SessionKey(data) {
  SessionKey(
    current_session: CurrentSession,
    key: String,
    decode: Decoder(data),
    encode: fn(data) -> String,
  )
}

Constructors

  • SessionKey(
      current_session: CurrentSession,
      key: String,
      decode: Decoder(data),
      encode: fn(data) -> String,
    )

Functions

pub fn delete(
  current_session: CurrentSession,
  key: String,
) -> Result(Session, SessionError)

Delete key from session

pub fn delete_session(
  current_session: CurrentSession,
) -> Result(Nil, SessionError)

Remove session Usage:

sessions.delete(store, req)
pub fn get(
  entry: SessionKey(a),
) -> Result(Option(a), SessionError)

Get data from session by key

pub fn get_session(
  current_session: CurrentSession,
) -> Result(Session, SessionError)

Try to get the session from the store. If it does not exist create a new one.

pub fn key(
  current_session: CurrentSession,
  key: String,
) -> SessionKey(String)
pub fn middleware(
  req: Request(Connection),
  config: Config,
  handle_request: fn(Request(Connection)) -> Response(Body),
) -> Response(Body)

Create a session if no session exists to make sure there always is a session_id to store data towards Usage:

use <- sessions.middleware(current_session)
pub fn replace_session(
  current_session: CurrentSession,
  res: Response(Body),
  new_session: Session,
) -> Result(Response(Body), SessionError)

Replace the session with a new one Usage:

wisp.ok() |> replace_session(new_session)
pub fn set(
  entry: SessionKey(a),
  data: a,
) -> Result(a, SessionError)

Set data in session by key

pub fn with_codec(
  session_key: SessionKey(a),
  decoder decode: fn(Dynamic) -> Result(b, List(DecodeError)),
  encoder encode: fn(b) -> String,
) -> SessionKey(b)
Search Document