tauri-axum-htmx

Crates.iotauri-axum-htmx
lib.rstauri-axum-htmx
version0.1.1
created_at2025-01-25 13:06:17.194375+00
updated_at2025-04-25 02:21:21.478031+00
descriptionBuild interactive UIs in Tauri applications using HTMX and Axum, enabling server-side rendering patterns by running the Axum app in the Tauri backend.
homepage
repositoryhttps://github.com/logankeenan/tauri-axum-htmx
max_upload_size
id1530591
size20,091
Logan Keenan (logankeenan)

documentation

README

Tauri Axum HTMX

Crates.io docs.rs npm version unpkg

Build interactive UIs in Tauri applications using HTMX and Axum, enabling server-side rendering patterns by running the Axum app in the Tauri backend.

Quick Overview

Enables server-side rendering patterns by:

  1. Intercepting HTMX requests in the webview
  2. Forwarding them through Tauri's FFI bridge
  3. Processing them with an Axum application running in the Tauri backend
  4. Returning HTML responses back to the webview be rendered by HTMX

Demo and example source:

https://github.com/user-attachments/assets/02923cc7-281c-4271-9f52-02ecee1ac588

Getting started

Create a vanilla Tauri project and initialize tauri-axum-htmx in src/index.html

<!doctype html>
<html lang="en">
  <head>
    <script src="https://unpkg.com/htmx.org@2.0.4"></script>
    <script type="module">
      import { initialize } from "https://unpkg.com/tauri-axum-htmx";

      initialize("/"); // the initial path for the application to start on
    </script
  </head>
</html>

Create a Tauri command to process requests from the webview

struct TauriState {
    router: Arc<Mutex<Router>>,
}

#[tauri::command]
async fn local_app_request(
    state: State<'_, TauriState>,
    local_request: LocalRequest,
) -> Result<LocalResponse, ()> {
    let mut router = state.router.lock().await;

    let response = local_request.send_to_router(&mut router).await;

    Ok(response)
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    let app = Router::new().route("/", get(|| async { "Hello, World!" }));

    let tauri_stat = TauriState {
        router: Arc::new(Mutex::new(router)),
    };

    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .manage(tauri_stat)
        .invoke_handler(tauri::generate_handler![local_app_request])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

JavaScript API

initialize(initialPath: string, localAppRequestCommandOverride: string)

  • initialPath: The initial path for the application to start on
  • localAppRequestCommandOverride: The name of the Tauri command to process requests from the webview
Commit count: 83

cargo fmt