Add WebAPIResponseEventStream for API streaming results.

Review Request #13281 — Created Sept. 21, 2023 and submitted

Information

Djblets
release-4.x

Reviewers

This builds upon the new EventStreamHttpResponse class to easily
enable APIs to stream events and results to callers using Server-Sent
Events.

WebAPIResource handlers 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 a X-Event-Data-Mimetype header to know the resource type for
any "message" events (the default when event isn'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 EventSource in JavaScript, verifying that events
were properly coming in and could be parsed correctly.

Summary ID
Add WebAPIResponseEventStream for API streaming results.
This builds upon the new `EventStreamHttpResponse` class to easily enable APIs to stream events and results to callers using Server-Sent Events. `WebAPIResource` handlers 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 a `X-Event-Data-Mimetype` header to know the resource type for any "message" events (the default when `event` isn'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.
b3e7dc50f6caa1e33e2ef15528c1c86a6f23b292
Description From Last Updated

'djblets.http.responses.EventStream' imported but unused Column: 1 Error code: F401

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
  1. Ship It!
  2. 
      
maubin
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-4.x (4e6e0b0)