Skip to content

Data types

TypeSpec.SSE

SSEStream

Describes a stream of server-sent events.

The content-type is set to text/event-stream.

The server-sent events are described by Type. The event type for any event can be defined by using named union variants. When a union variant is not named, it is considered a โ€˜messageโ€™ event.

model TypeSpec.SSE.SSEStream<Type>

Template Parameters

NameDescription
TypeThe set of models describing the server-sent events.

Examples

Mix of named union variants and terminal event
model UserConnect {
username: string;
time: string;
}
model UserMessage {
username: string;
time: string;
text: string;
}
model UserDisconnect {
username: string;
time: string;
}
@TypeSpec.Events.events
union ChannelEvents {
userconnect: UserConnect,
usermessage: UserMessage,
userdisconnect: UserDisconnect,
@Events.contentType("text/plain")
@terminalEvent
"[unsubscribe]",
}
op subscribeToChannel(): SSEStream<ChannelEvents>;

Properties

NameTypeDescription
contentType"text/event-stream"
bodystring