README

Datastar SDK examples

These examples port the demonstrations in datastar-go/cmd/examples to data-oriented Raku. They use only Datastar::SDK and Raku's socket API.

Run the commands from the repository root so Raku++ can load both the SDK and the private example HTTP adapter:

rakupp -Ilib -Iexamples/lib examples/helloworld/main.raku
rakupp -Ilib -Iexamples/lib examples/hotreload/main.raku

The examples also run with Rakudo:

raku -Ilib -Iexamples/lib examples/helloworld/main.raku
raku -Ilib -Iexamples/lib examples/hotreload/main.raku

Hello World

Open http://127.0.0.1:1337, choose a delay, and press Start. The browser sends the delay signal to /hello-world; the backend validates it and streams every prefix of Hello, world! as a complete element with the stable ID message.

Pass a different port as the first argument:

rakupp -Ilib -Iexamples/lib examples/helloworld/main.raku 8080

Hot reload

Open http://127.0.0.1:9001, then edit and save examples/hotreload/hotreload.html. The backend owns the file-change watch. The browser holds an SSE request to /hotreload; when the file changes, the backend streams a reload script and the browser reconnects.

This reproduces the Go example's browser behavior without requiring Reflex or another file-watcher dependency.

Pass a different port and page path as positional arguments:

rakupp -Ilib -Iexamples/lib \
  examples/hotreload/main.raku \
  9002 examples/hotreload/hotreload.html

Native binaries

Compile either server through Raku++'s native C++ path:

RAKULIB=lib:examples/lib \
  rakupp --exe examples/helloworld/main.raku -o /tmp/datastar-hello
RAKULIB=lib:examples/lib \
  rakupp --exe examples/hotreload/main.raku -o /tmp/datastar-hotreload

The compile step should report Compiled (native). Run the binaries from the repository root with the same RAKULIB value so their modules remain available:

RAKULIB=lib:examples/lib /tmp/datastar-hello
RAKULIB=lib:examples/lib /tmp/datastar-hotreload

The HTTP adapter under examples/lib is intentionally example infrastructure, not part of the public Datastar::SDK API.

Datastar::SDK v0.1.1

A data-oriented Datastar SDK for Raku

Authors

  • E. Alvarez

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Datastar::SDK

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.