Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created January 20, 2022 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubukoz/351c19621d475c319ab1d0a178bf9bf7 to your computer and use it in GitHub Desktop.
Save kubukoz/351c19621d475c319ab1d0a178bf9bf7 to your computer and use it in GitHub Desktop.
// using lib org.http4s::http4s-ember-server:0.23.7
// using lib org.http4s::http4s-circe:0.23.7
// using lib org.http4s::http4s-dsl:0.23.7
// using scala 2.13.7
// using options -Xsource:3.0 -Wunused:imports -deprecation
import cats.effect.IO
import cats.effect.IOApp
import io.circe.Decoder
import org.http4s.HttpRoutes
import org.http4s.circe.CirceEntityCodec._
import org.http4s.dsl.io._
import org.http4s.ember.server.EmberServerBuilder
object demo extends IOApp.Simple {
case class Foo(s: String)
implicit val decoder: Decoder[Foo] = Decoder.forProduct1("s")(Foo.apply)
def run: IO[Unit] =
EmberServerBuilder
.default[IO]
.withHttpApp {
HttpRoutes
.of[IO] { case req @ POST -> Root / "foo" => req.as[Foo] *> Ok() }
.orNotFound
}
.build
.useForever
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment