Skip to content

Sessions

Yuki Takei edited this page Oct 10, 2016 · 1 revision

Register SessionMiddleware into the middleware chains. See more detail for SessionMiddleware to visit https://github.com/slimane-swift/SessionMiddleware

import Slimane
import SessionMiddleware

let app = Slimane()

// SessionConfig
let sesConf = SessionConfig(
    secret: "my-secret-value",
    expires: 180,
    HTTPOnly: true
)

// Enable to use session in Slimane
app.use(SessionMiddleware(conf: sesConf))

app.use(.get, "/") { request, response, responder in
    var request = request
    // set data into the session
    request.session["foo"] = "bar"

    request.session.id // show session id

    response(.respond(response))
}

Available Session Stores

  • MemoryStore
  • SessionRedisStore
Clone this wiki locally