# Datastar SDK examples

These examples port the demonstrations in
[`datastar-go/cmd/examples`](https://github.com/starfederation/datastar-go/tree/main/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:

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

The examples also run with Rakudo:

```sh
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:

```sh
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:

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

## Native binaries

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

```sh
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:

```sh
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.
