Skip to content

Docs & example: SSE live updates via native EventSource API #7

@mkjsix

Description

@mkjsix

Objective

Add a working SSE example to the product-catalog demo and document the pattern in the developer guide. This implements the documentation track defined in #6.

Prerequisite

Developer guide

Add a dedicated SSE section to docs/DEVELOPERS_GUIDE.md. Content defined in #6:

  • EventSource API basics (connect, listen, close, auto-reconnect)
  • RESTHeart SSE endpoint format (/_streams/<name>)
  • Full working example using EventSource + htmx.ajax() for re-rendering
  • When to use SSE vs polling
  • Auth considerations
  • Guidance on high-frequency flows (client-side rendering, not SSR)

Product-catalog example

Wire one live update scenario in examples/product-catalog:

  • Product list (/shop/products) auto-refreshes when a product is inserted or deleted
  • Uses native EventSource connected to the RESTHeart change stream for the products collection
  • On event: calls htmx.ajax() to re-fetch and re-render the product list fragment
  • Demonstrates at least one visible live DOM update without a page reload

Update examples/product-catalog/README.md with:

  • Prerequisites (MongoDB replica set required for change streams)
  • How to trigger a visible update (e.g. insert a document via curl or the admin UI)

Acceptance criteria

  • SSE section added to developer guide
  • EventSource pattern documented with a complete working example
  • Auth and reconnect behaviour documented
  • High-frequency flows guidance included
  • Product-catalog example shows a live update
  • README run instructions are reproducible

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions