snickerdoodle - Advanced Cookie Management Maven Central

Snickerdoodle handles cookie persistence between application runs, it has a fully in memory implementation, and will follow RFC 6265 correctly. Meaning it works very similarly to how your browser manages its cookies. Snickerdoodle is a bit more opinionated than the http4s implementation.

Cookies are a persistent stateful resource between a client and server. However, maybe you run into an unexpected error, or someone sets a remember me token for a super long time, or maybe you would just prefer to avoid work if you can because you have the information already available.

Snickerdoodle is the cookie for you.

Quick Start

To use snickerdoodle in an existing SBT project with Scala 2.13 or a later version, add the following dependencies to your build.sbt depending on your needs:

libraryDependencies ++= Seq(
  "io.chrisdavenport" %% "snickerdoodle" % "<version>"
)

How to use

import cats.syntax.all._
import cats.effect._
import fs2.io.file.Path
import io.chrisdavenport.snickerdoodle._
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.client.middleware.CookieJar

// Create the cookie jar like so
val jarResource = SnCookieJarBuilder.default[IO]
  .withSqlitePersistence(Path("sample.sqlite"))
  .build
// jarResource: Resource[IO, CookieJar[IO]] = Bind(
//   source = Eval(
//     fa = Delay(
//       thunk = cats.effect.IO$$$Lambda$10800/1992850410@551dff96,
//       event = cats.effect.tracing.TracingEvent$StackTrace
//     )
//   ),
//   fs = io.chrisdavenport.snickerdoodle.SnCookieJarBuilder$$Lambda$10802/1263861961@2edad1fe
// )

// Typical way you generally make a client
val clientResource = EmberClientBuilder.default[IO].build
// clientResource: Resource[IO, org.http4s.client.Client[IO]] = Bind(
//   source = Pure(a = fs2.io.net.NetworkCompanionPlatform$$anon$1@108c0001),
//   fs = org.http4s.ember.client.EmberClientBuilder$$Lambda$10837/2003643160@11d05308
// )


val combined = (jarResource, clientResource).mapN{
  // Apply it to a client
  case (jar, client) => CookieJar(jar)(client)
}
// combined: Resource[IO, org.http4s.client.Client[IO[A]]] = Bind(
//   source = Bind(
//     source = Bind(
//       source = Eval(
//         fa = Delay(
//           thunk = cats.effect.IO$$$Lambda$10800/1992850410@551dff96,
//           event = cats.effect.tracing.TracingEvent$StackTrace
//         )
//       ),
//       fs = io.chrisdavenport.snickerdoodle.SnCookieJarBuilder$$Lambda$10802/1263861961@2edad1fe
//     ),
//     fs = cats.FlatMap$$Lambda$10838/1536354803@492c46cb
//   ),
//   fs = cats.Monad$$Lambda$10795/803042571@5af704f5
// )