A simple project defining http4s middleware for client-side session management. See the example project for a code example.
Add the following to your build.sbt:
resolvers += Resolver.bintrayRepo("hgiddens", "maven")
libraryDependencies += "com.github.hgiddens" %% "http4s-session-core" % <version>
You can then use the middleware/methods described below.
Enables session management for the wrapped Service. Sessions are JSON values, and are stored on the client as HTTP cookies – having been signed and encrypted. The signing/encryption is by way of a server secret, which should be a long (e.g. 128 bytes) random string, and which much not be disclosed. Sessions can be invalidated by changing the secret.
Serves a provided Response instead of using the wrapped Service if the request does not have a session.
The Session.sessionManagement middleware must be wrapping any Service or Middleware using these methods.
request.session– gets the session from the request.response.newSession– sets the provided value as the session in the response.response.clearSession– clears the session in the response.response.modifySession– modifies the session that is sent back to the client in response.
Heavily based on the awesome akka-http-session.