sttp.tapir.server.akkahttp.package.scala Maven / Gradle / Ivy
package sttp.tapir.server
import akka.http.scaladsl.model.ResponseEntity
import akka.http.scaladsl.model.ws.Message
import akka.stream.scaladsl.{Flow, Source}
import akka.util.ByteString
import sttp.capabilities.akka.AkkaStreams
import sttp.model.sse.ServerSentEvent
import sttp.tapir.{CodecFormat, StreamBodyIO, streamTextBody}
import java.nio.charset.Charset
package object akkahttp {
type AkkaResponseBody = Either[Flow[Message, Message, Any], ResponseEntity]
val serverSentEventsBody: StreamBodyIO[Source[ByteString, Any], Source[ServerSentEvent, Any], AkkaStreams] =
streamTextBody(AkkaStreams)(CodecFormat.TextEventStream(), Some(Charset.forName("UTF-8")))
.map(AkkaServerSentEvents.parseBytesToSSE)(AkkaServerSentEvents.serialiseSSEToBytes)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy