DEV Community

Alex Spinov
Alex Spinov

Posted on

Tauri 2 Has a Free API You're Not Using

Tauri 2 builds desktop AND mobile apps with web technologies, but the binary is 600KB instead of Electron's 150MB. Most developers don't know about the powerful Rust-to-JavaScript bridge.

The Free APIs You're Missing

1. Commands — Type-Safe Rust-JS Bridge

// src-tauri/src/lib.rs
#[tauri::command]
async fn read_file(path: String) -> Result<String, String> {
    std::fs::read_to_string(&path).map_err(|e| e.to_string())
}

#[tauri::command]
async fn fetch_data(url: String) -> Result<serde_json::Value, String> {
    let resp = reqwest::get(&url).await.map_err(|e| e.to_string())?;
    resp.json().await.map_err(|e| e.to_string())
}
Enter fullscreen mode Exit fullscreen mode
// Frontend
import { invoke } from "@tauri-apps/api/core";
const content = await invoke<string>("read_file", { path: "/tmp/data.txt" });
const data = await invoke<any>("fetch_data", { url: "https://api.example.com" });
Enter fullscreen mode Exit fullscreen mode

2. Plugin System — Extensible Architecture

// Tauri 2 plugins
tauri::Builder::default()
    .plugin(tauri_plugin_fs::init())      // File system access
    .plugin(tauri_plugin_shell::init())    // System commands
    .plugin(tauri_plugin_dialog::init())   // Native dialogs
    .plugin(tauri_plugin_store::init())    // Persistent KV storage
    .plugin(tauri_plugin_updater::init())  // Auto-updates
    .plugin(tauri_plugin_notification::init()) // System notifications
Enter fullscreen mode Exit fullscreen mode

3. Mobile Support — iOS and Android

# Add mobile targets
tauri android init
tauri ios init

# Run on mobile
tauri android dev
tauri ios dev
Enter fullscreen mode Exit fullscreen mode

Same codebase for desktop and mobile. One frontend, one Rust backend.

4. Event System — Bidirectional Communication

// Emit from Rust to frontend
app_handle.emit("download-progress", DownloadProgress { percent: 75, speed: "2.5 MB/s" })?;

// Listen from frontend
app_handle.listen("user-action", |event| {
    println!("User did: {}", event.payload());
});
Enter fullscreen mode Exit fullscreen mode
import { listen, emit } from "@tauri-apps/api/event";

await listen<{ percent: number }>("download-progress", (event) => {
  setProgress(event.payload.percent);
});

await emit("user-action", { action: "clicked-save" });
Enter fullscreen mode Exit fullscreen mode

5. Security — Capability-Based Permissions

// src-tauri/capabilities/default.json
{
  "identifier": "default",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "fs:allow-read-text-file",
    "fs:scope-home",
    "shell:allow-open",
    "dialog:allow-open",
    "store:default"
  ]
}
Enter fullscreen mode Exit fullscreen mode

Explicit permissions per window. Your app can't access what it doesn't need.

Getting Started

cargo install create-tauri-app
cargo create-tauri-app
npm run tauri dev
Enter fullscreen mode Exit fullscreen mode

Need data from any website delivered as clean JSON? I build production web scrapers that handle anti-bot, proxies, and rate limits. 77 scrapers running in production. Email me: Spinov001@gmail.com

Check out my awesome-web-scraping list for the best scraping tools and resources.

Top comments (0)