Hello Datastar

Datastar is a new-ish entry in the world of hypermedia-oriented ,htmx alternatives, with a distinct focus on Server-Sent Events. It describes itself thus:

Datastar brings the functionality provided by libraries like Alpine.js (frontend reactivity) and htmx (backend reactivity) together, into one cohesive solution. It's a lightweight, extensible framework that allows you to:
  1. Manage state and build reactivity into your frontend using HTML attributes.
  2. Modify the DOM and state by sending events from your backend.

I added Perl for Datastar with Datastar::SSE, for the backend reactivity bits.

Essentially a wrapper around the excellent HTTP::ServerEvent module, Datastar::SSE provides methods for all the SSE events currently supported by Datastar. Also included is a function that provides the recommended set of headers to include in Datastar SSE responses.

There is a fairly comprehensive example is /eg in the distribution, as well as a single file example in /eg/index.cgi

Leave a comment

About James

user-pic I blog about Perl.