Skip to content

Add opt-in SSE support for server-to-client Streaming Methods #6044

Backlog

Description

@onism0106

Problem to Solve

Serverpod 4.1.2 uses WebSockets for Streaming Methods, including methods that take ordinary arguments and return a Stream. For features like AI chat, the client sends its input once and receives incremental results. Using SSE today requires a custom Web Route and separate client code for authentication, event decoding, and cancellation. Serverpod Streaming Methods documentation

Proposal

Let developers choose WebSocket or Server-Sent Events (SSE) per Streaming Method. Keep WebSocket as the default and require it for methods with stream parameters. Allow SSE for methods that return Stream and accept only ordinary arguments.

For SSE, the generated client could send an authenticated HTTP POST and decode each SSE data: event into T. Application code would still consume a typed Stream. Cancelling the subscription should close the HTTP response stream and release the server-side resources.

Use Case

A Flutter chat app sends a prompt and receives text deltas and a completion event as the model generates a reply. The developer can choose SSE while keeping the generated client, typed events, and existing Serverpod authentication.

Alternatives

A custom SSE Web Route can reuse the same chat service. That’s the workaround we use today. Built-in support would let developers use SSE through the same typed endpoint API they already use for WebSocket streams.

Additional context

No response

How experienced are you with this library?

No response

Are you interested in working on a PR for this?

  • I want to work on this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions