1

I am creating an SSE simple example, I create an API with Scalatra and get responses by the interval with the header text/event-stream. It looks like Scalatra doesn't support this type. This is my simple code,

 get("/hello") {
    val headers = Map(
      "Cache-Control" -> "no-cache",
      "Content-Type" -> "text/event-stream",
      "Connection" -> "close")
    Ok("data: hello world", headers)
  }

But I only get a message from server. I want to do something like akka-http

get {
      complete {
        Source.tick(2.seconds, 2.seconds, ())
          .map(_ => LocalTime.now())
          .map(dateTimeToServerSentEvent)
          .via(WithHeartbeats(1.second))
      }
    }

Do you guys have any idea how to get a event-stream from by Scalatra? Thank you.

Paul R
  • 208,748
  • 37
  • 389
  • 560
Wilson Ho
  • 372
  • 5
  • 18

0 Answers0