Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Little Finch/Circe app, that shows how to get None not being emitted as Null
import cats.effect.IO
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.{Http, ListeningServer, Service}
import com.twitter.server.TwitterServer
import com.twitter.util.Await
import io.finch.catsEffect._
import io.finch._
import io.finch.circe.dropNullValues._
object FinchRestWithNoNulls extends TwitterServer {
final case class Foo(id: String, op: Option[String]=None)
def getFooList(a:String = "")= List(Foo("1", Option("hello")), Foo("2"))
val fooListApi: Endpoint[IO, List[Foo]] = get("v1" :: "foos" ) {
// Finch-finagle service
val apiService: Service[Request, Response] = Bootstrap.
serve[Application.Json] (fooListApi).toService
val port: Flag[Int] = flag("port", 8081, "TCP port for HTTP server")
def main(): Unit = {
val server: ListeningServer = Http.server.serve(s":${port()}", apiService)
println("Listening: " + port() )
onExit { server.close() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment