| Crates.io | tauri-plugin-axum |
| lib.rs | tauri-plugin-axum |
| version | 0.7.1 |
| created_at | 2025-08-14 18:59:26.543142+00 |
| updated_at | 2025-08-26 07:46:51.161136+00 |
| description | A Tauri plugin that allows calling Axum Router endpoints directly. |
| homepage | |
| repository | https://github.com/mcitem/tauri-plugin-axum |
| max_upload_size | |
| id | 1795284 |
| size | 154,011 |
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.
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
tauri::Builder::default().plugin(tauri_plugin_axum::init(Router::new()))
Once registered, you can access your Axum routes via:
axum://localhost/<path>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";
Rust crate:
cargo add tauri-plugin-axum
npm package:
pnpm i @mcitem/tauri-plugin-axum
Add required capability in src-tauri/capabilities/default.json:
{
// ...
"permissions": ["axum:default"]
// ...
}
// 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)
tauri::Builder::default().plugin(tauri_plugin_axum::init(Router::new()));
window.fetch("http://axum.localhost/");
#[derive(Serialize, Deserialize)]
struct Greet {
axum: String,
tauri: String,
}
async fn post_handle(Json(j): Json<Greet>) -> Json<Greet> {
Json(Greet {
axum: format!("axum, {}!", j.axum),
tauri: format!("tauri, {}!", j.tauri),
})
}
// Initialize router asynchronously
tauri::Builder::default()
.setup(|app| {
let path = app.path().app_config_dir()?;
app.handle().plugin(tauri_plugin_axum::block_init(async {
println!("Application config path: {:?}", path);
router::router()
}))?;
Ok(())
});
// 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 });
git clone https://github.com/mcitem/tauri-plugin-axum
cd tauri-plugin-axum
pnpm install
pnpm build
pnpm --filter tauri-app install
pnpm --filter tauri-app tauri dev