Module htmx

Module htmx 

Source
Expand description

HTMX response types and extractors

This module builds on axum-htmx with additional features:

  • Out-of-band swaps (HxSwapOob)
  • Automatic template detection (HxTemplate)
  • Smart response enum (HxResponse)

§Re-exported from axum-htmx

All request extractors and response helpers from axum-htmx are re-exported for convenience. See axum-htmx documentation for detailed usage.

§Out-of-Band Swaps

Use HxSwapOob to update multiple page elements in a single response:

use acton_htmx::htmx::{HxSwapOob, SwapStrategy};
use axum::response::Html;

async fn update_with_oob() -> impl axum::response::IntoResponse {
    let mut oob = HxSwapOob::new();

    // Update main content
    oob.add("main-content", "<p>New main content</p>", SwapStrategy::InnerHTML);

    // Update notification badge
    oob.add("notification-count", "<span>5</span>", SwapStrategy::InnerHTML);

    // Update flash messages
    oob.add("flash-container", r#"<div class="alert">Success!</div>"#, SwapStrategy::InnerHTML);

    oob
}

Structs§

AutoVaryLayer
Addresses htmx caching issues by automatically adding a corresponding Vary header when [HxRequest], [HxTarget], [HxTrigger], [HxTriggerName] or their combination is used.
HxBoosted
The HX-Boosted header.
HxCurrentUrl
The HX-Current-Url header.
HxHistoryRestoreRequest
The HX-History-Restore-Request header.
HxLocation
The HX-Location header.
HxPrompt
The HX-Prompt header.
HxPushUrl
The HX-Push-Url header.
HxRedirect
The HX-Redirect header.
HxRefresh
The HX-Refreshheader.
HxReplaceUrl
The HX-Replace-Url header.
HxRequest
The HX-Request header.
HxRequestGuardLayer
Checks if the request contains the HX-Request header, redirecting to the given location if not.
HxReselect
The HX-Reselect header.
HxResponseTrigger
The HX-Trigger* header.
HxReswap
The HX-Reswap header.
HxRetarget
The HX-Retarget header.
HxSwapOob
Out-of-band swap container
HxTarget
The HX-Target header.
HxTrigger
The HX-Trigger header.
HxTriggerName
The HX-Trigger-Name header.

Enums§

SwapStrategy
HTMX swap strategy for out-of-band updates