SSESessionWithDeserialization
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)
}
}
}
}
Content copied to clipboard
To learn more, see the SSE and the SSE specification.
Inheritors
Properties
Functions
Link copied to clipboard
Returns a diagnostic buffer of SSE data that has already been processed by this session.
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.