HTMX Engine Server
TsgcHTMX_Engine_Server — handles htmx partial-page swap requests over HTTP and broadcasts live out-of-band fragments to all connected browsers over WebSocket.
TsgcHTMX_Engine_Server — handles htmx partial-page swap requests over HTTP and broadcasts live out-of-band fragments to all connected browsers over WebSocket.
Bridges htmx's HTTP-driven partial updates with WebSocket server-push. Incoming htmx requests are dispatched to OnHTMXMessage; your handler returns only the fragment to swap in. Call BroadcastFragment at any time to push live out-of-band updates to every connected browser.
TsgcHTMX_Engine_Server
htmx swaps + live server push
Delphi, C++ Builder, .NET
Wire the engine to your WebSocket server, handle partial-swap requests in OnHTMXMessage, and call BroadcastFragment to push updates to every connected browser.
uses
sgcHTMX_Engine_Server;
var
oHTMX: TsgcHTMX_Engine_Server;
begin
oHTMX := TsgcHTMX_Engine_Server.Create(nil);
oHTMX.Server := WSSServer;
oHTMX.OnHTMXMessage := HandleHTMXRequest;
// later, from any thread, push a KPI update:
oHTMX.BroadcastFragment(
'<div id="kpi-revenue" hx-swap-oob="true">' +
CurrToStr(FRevenue) + '</div>');
end;
TsgcHTMX_Engine_Server *oHTMX = new TsgcHTMX_Engine_Server(NULL);
oHTMX->Server = WSSServer;
oHTMX->OnHTMXMessage = HandleHTMXRequest;
// push a live update:
oHTMX->BroadcastFragment(
"<div id=\"kpi-revenue\" hx-swap-oob=\"true\">" +
CurrToStr(FRevenue) + "</div>");
var htmx = new TsgcHTMX_Engine_Server();
htmx.Server = wssServer;
htmx.OnHTMXMessage += HandleHTMXRequest;
// push a live update:
htmx.BroadcastFragment(
"<div id=\"kpi-revenue\" hx-swap-oob=\"true\">" +
revenue.ToString("N0") + "</div>");
The members you reach for most often.
The TsgcHTTPServer this engine attaches to, which handles the HTTP partial-swap requests. Assign a TsgcWSHTTPServer when the WebSocket server is installed to add WebSocket push.
Event fired for every htmx-triggered HTTP request; your handler returns just the fragment HTML to swap in.
Sends an out-of-band htmx payload to every currently connected WebSocket client simultaneously.
Called by the host server for each request; identifies htmx headers and routes to OnHTMXMessage or falls through.
htmx's out-of-band swap attribute: the fragment id must match the target element id on the page.
BroadcastFragment is thread-safe; call it from background timers, push threads or event handlers without locking.
Assign a TsgcHTMLAuth to Auth and the engine applies the session, the CSRF check and the login and role rules of the routes to every request. MessageSession returns the session of a WebSocket connection.
SSE.Enabled serves the event stream, and a Template.Transport of htSSE or htAuto lets a page receive its fragments over server-sent events. PushFragment and BroadcastFragment stay the same.
Runs a request through the router and the engine without a socket, which is how the tests of your pages call them.
| Online HelpFull API reference and usage guide for this component. | Open | |
| All sgcHTML ComponentsBrowse the full feature matrix of 80+ components. | Open | |
| Download Free TrialThe 30-day trial ships the 60.HTML demo projects. | Open | |
| PricingSingle, Team and Site licenses with full source code. | Open |