Closed adamw closed 5 months ago
Wouldn't that be a asSSEAlways
?
For all other streaming approaches we simply offer a SSE-parsing stream stage, e.g.: https://sttp.softwaremill.com/en/stable/backends/akka.html#server-sent-events
asSSEAlways
is hard to do generically, as you don't know what's the stream type underneath. So it could be done, but would need to be backend-specific
The default backend is already fully usable for direct style Scala, along with streaming (via
InputStream
bodies), and web sockets (using theWebSocket
's blocking.send()
and.receive()
methods).However, what we are missing is integration with SSE, streaming websockets (sometimes its more convenient to work this way) and high-level streaming (mapping over byte chunks or lines, for example).
That's why it might reasonable to have an Ox integration module. In fact, this is a joint Ox+sttp-client issue, as it requires changes in both. Going from the end:
Source
, such as two-way conversions between anInputStream
and aSource[byte chunk]
; between anInputStream
and aSource[String]
(lines); and finally writing such sources to files/reading from files. What remains to be determined here is what's a good representation of abyte chunk
. A simpleArray[Byte]
?ByteBuffer
? Pekko'sBytString
?WebSocket
and a(Source[WebSocketFrame], Sink[WebSocketFrame]
Example usage: