Created
April 8, 2026 11:41
-
-
Save keynmol/135b2241750ac473064368da9fea70b2 to your computer and use it in GitHub Desktop.
http4s on scala native 0.5
This file contains hidden or 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 scala 3.8.3 | |
| //> using platform native | |
| //> using nativeVersion 0.5.11 | |
| //> using repository central:maven-snapshots | |
| //> using dep org.http4s::http4s-ember-server::0.23.33-145-96299c2-SNAPSHOT | |
| //> using dep org.http4s::http4s-dsl::0.23.33-145-96299c2-SNAPSHOT | |
| //> using dep org.http4s::http4s-circe::0.23.33-145-96299c2-SNAPSHOT | |
| //> using dep com.outr::scribe-cats::3.19.0 | |
| //> using option -Wunused:all | |
| import io.circe.* | |
| import org.http4s.ember.server.EmberServerBuilder | |
| import org.http4s.dsl.io.* | |
| import org.http4s.circe.CirceEntityCodec.* | |
| import org.http4s.* | |
| import cats.effect.* | |
| import scala.concurrent.duration.* | |
| case class Resp(x: String) derives Codec.AsObject | |
| object Main extends IOApp.Simple: | |
| val log = scribe.cats.io | |
| val routes = HttpRoutes.of[IO] { case GET -> Root / "hello" / name => | |
| log.info(s"Received a request for $name") *> | |
| Ok(Resp(name)) | |
| } | |
| override def run = | |
| EmberServerBuilder | |
| .default[IO] | |
| .withHttpApp(routes.orNotFound) | |
| .withShutdownTimeout(1.second) | |
| .build | |
| .evalTap(server => log.info(s"Server started on ${server.baseUri}")) | |
| .useForever | |
| end Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment