Quick Start

This guide walks you through creating your first session-enabled application.

Step 1: Define Session Data

Create a struct that includes Session::SessionData:

require "session"

struct UserSession
  include Session::SessionData

  property user_id : Int64?
  property username : String?
  property email : String?
  property role : String = "guest"
  property login_time : Time?

  def authenticated? : Bool
    !user_id.nil?
  end

  def admin? : Bool
    role == "admin"
  end
end

Step 2: Configure Session

Set up the session configuration:

Step 3: Use Sessions

Create a Session

Retrieve a Session

Update a Session

Delete a Session

Step 4: HTTP Integration

Integrate with an HTTP server:

Step 5: Add Flash Messages

Use flash messages for one-time notifications:

Complete Example

Next Steps

Last updated

Was this helpful?