Data types
TypeSpec.SSE
Section titled “TypeSpec.SSE”SSEStream
Section titled “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
Section titled “Template Parameters”| Name | Description |
|---|---|
| Type | The set of models describing the server-sent events. |
Examples
Section titled “Examples”Mix of named union variants and terminal event
Section titled “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.eventsunion ChannelEvents { userconnect: UserConnect, usermessage: UserMessage, userdisconnect: UserDisconnect,
@Events.contentType("text/plain") @terminalEvent "[unsubscribe]",}
op subscribeToChannel(): SSEStream<ChannelEvents>;Properties
Section titled “Properties”| Name | Type | Description |
|---|---|---|
| contentType | "text/event-stream" | |
| body | string |