| Crates.io | tauri-axum-htmx |
| lib.rs | tauri-axum-htmx |
| version | 0.1.1 |
| created_at | 2025-01-25 13:06:17.194375+00 |
| updated_at | 2025-04-25 02:21:21.478031+00 |
| description | Build interactive UIs in Tauri applications using HTMX and Axum, enabling server-side rendering patterns by running the Axum app in the Tauri backend. |
| homepage | |
| repository | https://github.com/logankeenan/tauri-axum-htmx |
| max_upload_size | |
| id | 1530591 |
| size | 20,091 |
Build interactive UIs in Tauri applications using HTMX and Axum, enabling server-side rendering patterns by running the Axum app in the Tauri backend.
Enables server-side rendering patterns by:
Demo and example source:
https://github.com/user-attachments/assets/02923cc7-281c-4271-9f52-02ecee1ac588
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");
}
initialize(initialPath: string, localAppRequestCommandOverride: string)
initialPath: The initial path for the application to start onlocalAppRequestCommandOverride: The name of the Tauri command to process requests from the webview