ff4s - Feature Flags For Scala

Goals

Installing

libraryDependencies += "io.cardell" %%% "ff4s-flipt-server-sdk" % "0.0.1"

Usage

import cats.effect.IO
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.Uri
import io.cardell.ff4s.flipt.FliptApi
import io.cardell.ff4s.flipt.EvaluationRequest
import io.cardell.ff4s.flipt.auth.AuthenticationStrategy

val url: Uri = Uri.unsafeFromString("https://flipt.example.com")
// url: Uri = Uri(
//   scheme = Some(value = Scheme(https)),
//   authority = Some(
//     value = Authority(
//       userInfo = None,
//       host = RegName(host = flipt.example.com),
//       port = None
//     )
//   ),
//   path = ,
//   query = ,
//   fragment = None
// )
val token: String = "token"
// token: String = "token"

val resource = EmberClientBuilder
    .default[IO]
    .build
    .map(client =>
        FliptApi[IO](client, url, AuthenticationStrategy.ClientToken("token"))
    )
// resource: cats.effect.kernel.Resource[IO, FliptApi[IO]] = Bind(
//   source = Bind(
//     source = Eval(fa = Pure(value = ())),
//     fs = org.http4s.ember.client.EmberClientBuilder$$Lambda$11697/0x000000010313e840@1b124b24
//   ),
//   fs = cats.effect.kernel.Resource$$Lambda$11698/0x000000010313d840@3cacddc
// )

resource.use { flipt => 
    for {
        res <- flipt.evaluateBoolean(
            EvaluationRequest(
                namespaceKey = "default",
                flagKey = "my-flag-1",
                entityId = None,
                context = Map.empty,
                reference = None
            )
        )
    } yield res.enabled
}
// res0: IO[Boolean] = FlatMap(
//   ioe = Pure(value = ()),
//   f = cats.effect.kernel.Resource$$Lambda$11700/0x000000010313c040@63fe5c91,
//   event = cats.effect.tracing.TracingEvent$StackTrace
// )