Skip to content

Strings as SSE event IDs #1040

Description

@jmalloc

The current SSE API models event IDs as non-zero integers. This appears to be more restrictive than the SSE specification, which describes the value as an "event ID string". See https://html.spec.whatwg.org/dev/server-sent-events.html#the-last-event-id-header

The current API prevents valid SSE use cases such as:

  • UUIDs
  • Opaque cursor tokens
  • Composite identifiers (e.g. stream-123:456)
  • Explicitly using 0 as an event ID (useful when talking about offsets into a stream)

Would it be possible to add support for strings? This would more closely match both the SSE specification.

I'm happy to submit a PR if a project maintainer could advise an approach. My instinct is to add an IDString string field alongside ID int and mark ID as deprecated. The string value would take precedence over the integer value if both are present. If having two separate fields is not desirable, an as an alternative, we could relax ID type to any and perform stringification dynamically, but I'd argue the two-field approach is clearer.

cc @danilvpetrov

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions