Hey, I found on youtrack that there appears to be ...
# ktor
c
Hey, I found on youtrack that there appears to be plugins for sse for both server and client in 3.0.0, is it written anywhere which eap artifacts are needed to experiment with this? Sorry if it’s obvious and I couldn’t find it
a
You can check out the SSE plugins (
io.ktor:ktor-server-sse
and
io.ktor:ktor-client-core
) using the
3.0.0-eap-786
version.
c
Amazing thanks
I can’t seem to get a combination of
io.ktor:ktor-server-sse:3.0.0-eap-786
and
io.ktor.plugin
to run, any advice? Also on another note we use
Resources
for all other endpoints - is it possible to use it with
sse
to avoid having to define the path manually? Thanks again
a
Unfortunately, the current version of the Ktor Gradle plugin is incompatible with the EAP version. You can use the constructor of the
SSEServerContent
class to send SSE events in the handler of a resource route.
Copy code
embeddedServer(Netty, port = 4444) {
    install(SSE)
    install(Resources)
    routing {
        get {
            call.respondText(contentType = ContentType.Text.Html) { """
                <html>
                    <body>
                    <script>
                        const evtSource = new EventSource("/sse");
                        evtSource.onmessage = (event) => {
                            console.log(event.data);
                        };
                    </script>
                    </body>
                </html>
            """.trimIndent() }
        }
        get<SseEndpoint> {
            call.respond(SSEServerContent(call) {
                send(ServerSentEvent("hello"))
            })
        }
    }
}.start(wait = true)
c
That’s great thanks! Any chance of blog post / news talking about the road to 3.0 any time soon? 😁