Hi, does http4k client support receiving SSE? If s...
# http4k
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)...
nope. 🙂
Haven’t try it but found this Java example https://github.com/nicferrier/java-simple-sse-client
This OkHttp extension seems simpler to use as inspiration https://github.com/heremaps/oksse
I did a very fast rip off of the OkHttp one (just quick fixes of IntelliJ Kotlin from Java transcoding) https://github.com/razvn/http4kbase/tree/test_sse 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… https://github.com/biowink/oksse
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
Copy code
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).body.stream.bufferedReader().forEachLine {
            if (it.startsWith("End")) throw Exception("End")
đź‘Ť 1