Skip to content

HttpApi: Support Server Sent Events #6048

@Avaq

Description

@Avaq

What is the problem this feature would solve?

I would like to specify how my event-stream response is encoded when creating my HttpApiEndpoint, and for that to generate the appropriate OpenAPI 3.2 JsonSchema:

{
  "text/event-stream": {
    "schema": {"type": "string"},
    "itemSchema": {"$ref": "#/components/schemas/MyEventSchema"}
  }
}

( see https://www.openapis.org/blog/2025/09/23/announcing-openapi-v3-2#sequential-and-streaming-data )

And I guess also make it so the generated HttpApiClient automatically creates an Effect Stream with the decoded events inside, and the server implementation won't need manual encoding of the events to text.

What is the feature you are proposing to solve the problem?

Something like this:

HttpApiSchema.withEncoding(MyEventSchema, {
  kind: 'EventStream', //<--- currently not supported
})

Or this, if it makes more sense:

HttpApiSchema.withEncoding(S.String, {
  kind: 'Text',
  contentType: 'text/event-stream',
  itemSchema: MyEventSchema, //<--- currently not supported
})

What alternatives have you considered?

For now the best option I found is using an OpenApi.Transform annotation and manually injecting all my event stream types into the components, and manually setting an itemSchema property on my my text/event-stream endpoints after defining them like this:

HttpApiSchema.withEncoding(S.String, {
  kind: 'Text',
  contentType: 'text/event-stream',
})

And for the generated client, manually decoding the EventSource to a Stream.

And for the server implementation, manually encoding the Stream items to Text Buffers.

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions