Effects Http On Mount

Run an HTTP request once on mount and display body, status, and headers.

Effect: HTTP on mount

HTTP status =

Body:

Response Headers:

null

This runs once on mount. Adjust the URL if your dev server exposes a different endpoint.

PHP
<?php $bodyAtom = state(null); $statusAtom = state(null); $headersAtom = state(null); $app = fragment([ el('div', [attrs(['class' => 'container p-3'])], [ el('h1', [], [ text('Effect: HTTP on mount') ]), el('p', [], [ text(concat('HTTP status = ', read($statusAtom))) ]), el('p', [], [ text('Body:') ]), el('pre', [cls('bg-light p-2')], [ text(read($bodyAtom)) ]), el('p', [cls('mt-2')], [ text('Response Headers:') ]), el('pre', [cls('bg-light p-2')], [ text(stringify(read($headersAtom))) ]), el('p', [cls('text-muted mt-3')], [ text('This runs once on mount. Adjust the URL if your dev server exposes a different endpoint.') ]), ]), // EFFECT: perform GET and store result atoms (body as text for easy display) onMount([ // url, method, to, status, headers, body, parse, asAction=true http( val('/api/ping/'), 'GET', $bodyAtom, $statusAtom, [ 'Content-Type' => 'application/x-www-form-urlencoded' ], null, 'text', true, $headersAtom ) ]), ]);