02/21/2021, 12:20 AM
Hi, does http4k client support receiving SSE? If so, is there any information on how to implement that? I can't seem to find any info on that on the project site (only the server side or so it looks for me)...


02/21/2021, 10:04 AM
nope. 🙂


02/21/2021, 11:39 AM
Haven’t try it but found this Java example
This OkHttp extension seems simpler to use as inspiration
I did a very fast rip off of the OkHttp one (just quick fixes of IntelliJ Kotlin from Java transcoding) calling from a browser http://localhost:9000/{name} will launch a SseClient that calls the SseServer with the same url http://localhost:9000/{name} that sends some data and events. The thing I see so far that does not work as I expected, when the client closes didn’t see the server onclose message sent to the client.
Why didn’t I think searching
Kotlin SSE client
directly instead of Java… I would have found directly this implementation…
Fan fact as it’s http, you can also just do a long stream with with the current client and just parse the received strings
object StreamSSE {
    operator fun invoke(req: Request) {
        val request = req
                    "Accept-Encoding" to "",
                    "Accept" to "text/event-stream",
                    "Cache-Control" to "no-cache",
        val noTimeoutClient = PreCannedOkHttpClients
        OkHttp(client = noTimeoutClient, bodyMode = BodyMode.Stream).debug()(request) {
            if (it.startsWith("End")) throw Exception("End")
👍 1