Fetch (SSE)
@get and @post send signals to the server via SSE. data-indicator shows loading state. The connection is request-response (not persistent).
datastar ds-fetch
Usage
// GET — sends all signals as query params, streams response events
data-on:click="@get('/api/items')"
// POST — sends signals as JSON body
data-on:click="@post('/api/save')"
// Filter signals sent (default: exclude _ prefixed)
data-on:click="@get('/api/search', {filterSignals: {include: /^q/}})"
// Loading indicator — sets aria-busy + data-loading attribute
data-indicator:fetching
// use in CSS: [data-loading] { opacity:.5 }
// or show a spinner:
data-show="$fetching" // $fetching is true while SSE open
// Server side (Go):
sse := datastar.NewSSE(c.Response().Writer, c.Request())
sse.PatchElements(web.RenderToString(myFragment))
datastar.MarshalAndPatchSignals(sse, map[string]any{"loading": false})