Add WebAPIResponseEventStream for API streaming results.
Review Request #13281 — Created Sept. 21, 2023 and submitted — Latest diff uploaded
This builds upon the new
EventStreamHttpResponseclass to easily
enable APIs to stream events and results to callers using Server-Sent
Events.
WebAPIResourcehandlers can now return a generator or generator
function that yields messages for the event stream. These will be
serialized one-by-one using the same API response serialization logic we
otherwise use for the API. Callers can parse those as they come in,
utilizing aX-Event-Data-Mimetypeheader to know the resource type for
any "message" events (the default wheneventisn't specified) to
intelligently handle parsing.This can be used for HTTP GET/POST/PUT requests, making it possible to
stream progress notification or build a message bus using the API.
Unit tests pass.
Tested this with an
EventSourcein JavaScript, verifying that events
were properly coming in and could be parsed correctly.