tauri-plugin-axum
A Tauri plugin that integrates the Axum web framework directly into your Tauri application. It provides a convenient way to expose APIs via custom protocols or through an HTTP-like interface inside the Tauri WebView.
✨ Features
-
Custom protocol registration
// Important: if you use a custom protocol, register it *before* the setup hook. // https://docs.rs/tauri/2.8.2/tauri/plugin/struct.Builder.html#known-limitations default.plugin
Once registered, you can access your Axum routes via:
- macOS, iOS, and Linux:
axum://localhost/<path> - Windows and Android:
http://axum.localhost/<path>(default)
⚠️ Note: Custom protocols currently do not support streaming.
-
Partial stream body support
Supports streaming responses using either the provided fetch API or an Axios adapter:
import { fetch } from "@mcitem/tauri-plugin-axum/fetch"; import { Adapter } from "@mcitem/tauri-plugin-axum/axios";
📦 Installation
Rust crate:
npm package:
Add required capability in src-tauri/capabilities/default.json:
{
// ...
"permissions": ["axum:default"]
// ...
}
🚀 Usage Example
Rust
// URI scheme protocols are registered when the WebView is created.
// If the plugin is registered after a WebView has been created,
// the protocol will not be available.
//
// macOS, iOS, Linux: axum://localhost/<path>
// Windows, Android: http://axum.localhost/<path> (default)
default.plugin;
window.fetch;
async
// Initialize router asynchronously
default
.setup;
TypeScript
// Using fetch
import { fetch } from "@mcitem/tauri-plugin-axum/fetch";
fetch("/", { method: "GET" })
.then((res) => res.text())
.then((res) => console.log(res));
// Using Axios adapter
import axios from "axios";
import { Adapter } from "@mcitem/tauri-plugin-axum/axios";
const instance = axios.create({ adapter: Adapter });
📚 Example Project
Run Example