SSESessionWithDeserialization

interface SSESessionWithDeserialization : CoroutineScope

A session with deserialization support for handling Server-Sent Events (SSE) from a server.

Example of usage:

client.sse({
url("http://localhost:8080/serverSentEvents")
}, deserialize = {
typeInfo, jsonString ->
val serializer = Json.serializersModule.serializer(typeInfo.kotlinType!!)
Json.decodeFromString(serializer, jsonString)!!
}) { // `this` is `ClientSSESessionWithDeserialization`
incoming.collect { event: TypedServerSentEvent<String> ->
when (event.event) {
"customer" -> {
val customer: Customer? = deserialize<Customer>(event.data)
}
"product" -> {
val product: Product? = deserialize<Product>(event.data)
}
}
}
}

To learn more, see the SSE and the SSE specification.

Report a problem

Inheritors

Properties

Link copied to clipboard
Link copied to clipboard
abstract val deserializer: (TypeInfo, String) -> Any?

Deserializer for transforming the data field of a ServerSentEvent into a desired data object.

Link copied to clipboard
abstract val incoming: Flow<TypedServerSentEvent<String>>

An incoming Server-Sent Events (SSE) flow.

Functions

Link copied to clipboard

Deserialize the provided event data into an object of type T using the deserializer function defined in the SSESessionWithDeserialization interface.

Deserialize the provided data into an object of type T using the deserializer function defined in the SSESessionWithDeserialization interface.