Add support for converting HTTP connections into SSE connections #1256
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
Adds support to be able to convert an HTTP connection into an SSE connection, allowing you to stream events from the server to connected clients.
At its simplest, you can convert an HTTP connection in a Route's scriptblock into an SSE connection using the new
ConvertTo-PodeSseConnection
function. You'll then be able to send events to one or more connected clients usingSend-PodeSseEvent
.SSE connections can be Locally or Globally scoped. Locally scoped connections will follow the normal HTTP request lifecycle, whereby the request will be closed once the Route has been dealt with. Globally scoped connections will be kept open and cached internally so that events can be streamed to them later on. Global is the default.
SSE connections can be used mostly on the frontend, using the
EventSource
class in JavaScript.Related Issue
Resolves #1245
Examples
The following will convert requests to
/events
into global SSE connections, and then a Schedule will send events to them every minute:The following will convert requests to
/events
into local SSE connections, and two events will be sent back to the client before the connection is closed: