Last active
October 12, 2023 16:11
-
-
Save windymelt/4748260bdc3c83ae4684db9afef91459 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 scala 3.3.0 | |
//> using dep org.http4s::http4s-ember-server:0.23.23 | |
//> using dep org.http4s::http4s-dsl:0.23.23 | |
import cats.effect._ | |
import com.comcast.ip4s._ | |
import org.http4s.HttpRoutes | |
import org.http4s._ | |
import org.http4s.dsl.io._ | |
import org.http4s.ember.server._ | |
import fs2.Stream | |
import scala.concurrent.duration._ | |
case class Song(title: String, releasedYear: Int, artist: String) | |
object Main extends IOApp.Simple { | |
val clockEverySeconds: Stream[IO, String] = Stream | |
.awakeEvery[IO](1.second) | |
.evalMap(_ => IO(java.time.OffsetDateTime.now().toString())) | |
.intersperse("\n") | |
val routes = HttpRoutes.of[IO] { case GET -> Root => | |
Ok(clockEverySeconds) | |
} | |
def run: IO[Unit] = | |
EmberServerBuilder | |
.default[IO] | |
.withHost(ipv4"0.0.0.0") | |
.withPort(port"8080") | |
.withHttpApp(routes.orNotFound) | |
.build | |
.useForever | |
.as(ExitCode.Success) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment