sse
Adds a route to handle Server-Sent Events (SSE) at the specified path using the provided handler. Requires SSE plugin to be installed.
Parameters
A URL path at which to handle Server-Sent Events (SSE) requests.
A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE endpoint. Inside the handler, you can use the functions provided by ServerSSESessionWithSerialization to send events to the connected clients.
Example of usage:
install(SSE)
routing {
sse("/events") {
repeat(100) {
send(ServerSentEvent("event $it"))
}
}
}
To learn more, see the SSE and the SSE specification.
See also
Adds a route to handle Server-Sent Events (SSE) using the provided handler. Requires SSE plugin to be installed.
Parameters
A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE endpoint. Inside the handler, you can use the functions provided by ServerSSESessionWithSerialization to send events to the connected clients.
Example of usage:
install(SSE)
routing {
sse {
repeat(100) {
send(ServerSentEvent("event $it"))
}
}
}
To learn more, see the SSE and the SSE specification.
See also
Adds a route to handle Server-Sent Events (SSE) at the specified path using the provided handler. Requires SSE plugin to be installed.
Parameters
A URL path at which to handle Server-Sent Events (SSE) requests.
A function to serialize data objects into the data
field of a ServerSentEvent
.
A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE endpoint. Inside the handler, you can use the functions provided by ServerSSESessionWithSerialization to send events to the connected clients.
Example of usage:
install(SSE)
routing {
sse("/json", serialize = { typeInfo, it ->
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
Json.encodeToString(serializer, it)
}) {
send(Customer(0, "Jet", "Brains"))
send(Product(0, listOf(100, 200)))
}
}
To learn more, see the SSE and the SSE specification.
See also
Adds a route to handle Server-Sent Events (SSE) using the provided handler. Requires SSE plugin to be installed.
Parameters
A function to serialize data objects into the data
field of a ServerSentEvent
.
A function that defines the behavior of the SSE session. It is invoked when a client connects to the SSE endpoint. Inside the handler, you can use the functions provided by ServerSSESessionWithSerialization to send events to the connected clients.
Example of usage:
install(SSE)
routing {
sse(serialize = { typeInfo, it ->
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
Json.encodeToString(serializer, it)
}) {
send(Customer(0, "Jet", "Brains"))
send(Product(0, listOf(100, 200)))
}
}
To learn more, see the SSE and the SSE specification.