Created
January 20, 2022 16:26
-
-
Save kubukoz/351c19621d475c319ab1d0a178bf9bf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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