Class: EventStreamResponse<T>
@divine/web-service.EventStreamResponse
Server-Sent Events (SSE) WebResponse serializer/helper class.
Type parameters
Name | Type | Description |
---|---|---|
T | unknown | The type of events to transmit. |
Hierarchy
↳
EventStreamResponse
Constructors
constructor
• new EventStreamResponse<T
>(source
, dataType?
, headers?
, keepaliveTimeout?
)
Converts an AsyncIterable
into a Server-Sent Event response stream.
Each object yielded by the source
generator will be serialized and converted to an SSE event. Symbols from the
EventAttributes interface may be added to transmit event metadata. null
or undefined
values will
result in a comment event. If no value is emitted for keepaliveTimeout
milliseconds, a comment line will be
sent automatically, in order to signal to the client that the server is still alive and the connection is open.
Exceptions from the generator will be serialized and sent as events of type error
.
Type parameters
Name | Type | Description |
---|---|---|
T | unknown | The type of events to transmit. |
Parameters
Name | Type | Description |
---|---|---|
source | AsyncIterable <undefined | null | T | T & EventAttributes > | The AsyncIterable which yields events to transmit. |
dataType? | string | ContentType | The format of the individual events. Default is JSON. |
headers? | WebResponseHeaders | Custom response headers to send. |
keepaliveTimeout? | number | How often, in milliseconds, to automatically send comments/keep-alive lines. |
Overrides
Defined in
web-service/src/helpers.ts:230
Properties
body
• body: null
| Buffer
| ReadableStream
The response body.
Inherited from
Defined in
web-service/src/response.ts:22
headers
• headers: WebResponseHeaders
= {}
The HTTP headers to return. If the length of the response body is known, content-length
will be
added automatically.
Inherited from
Defined in
web-service/src/response.ts:35
status
• status: WebStatus
The HTTP status code to return.
Inherited from
Defined in
web-service/src/response.ts:35
Methods
close
▸ close(): Promise
<void
>
Closes the response by destroying the body, in case it is a readable stream.
Returns
Promise
<void
>
Inherited from
Defined in
web-service/src/response.ts:80
serialize
▸ serialize(webreq
, config
): Promise
<RawResponse
>
Serializes the response.
For successful GET
and HEAD
responses, if an etag
response header matches the if-none-match
request
header, NOT_MODIFIED will be returned instead.
If returnRequestID is configured, the request ID will also be automatically added to the response.
Parameters
Name | Type | Description |
---|---|---|
webreq | WebRequest | The request this is a response to. |
config | Required <WebServiceConfig > | The WebService configuration. |
Returns
Promise
<RawResponse
>
A serialized response.
Inherited from
Defined in
web-service/src/response.ts:99
setHeader
▸ setHeader(name
, value
): EventStreamResponse
<T
>
Adds a custom header to the list of headers to return.
Parameters
Name | Type | Description |
---|---|---|
name | string | The name of the header to return (case-insensitive). |
value | undefined | string | number | boolean | string [] | The header value. |
Returns
This WebResponse.
Inherited from
Defined in
web-service/src/response.ts:73
toString
▸ toString(): string
Returns a short description about this response, including status and content type.
Returns
string