DEV Community

Alex Spinov
Alex Spinov

Posted on

Tauri v2 Has a Free API You've Never Heard Of

Tauri v2 lets you build desktop AND mobile apps from a single codebase using web technologies. Unlike Electron, Tauri apps are tiny (2-5MB), fast, and use the system's native webview. Version 2 adds iOS, Android, and a powerful plugin API.

What Makes Tauri v2 Special?

  • Multi-platform — desktop + mobile from one codebase
  • Tiny binaries — 2-5MB vs Electron's 100MB+
  • System webview — no bundled Chromium
  • Rust backend — write native code when you need performance
  • Plugin system — first-class API for extending functionality

The Hidden API: IPC Bridge

Tauri's IPC system lets JavaScript call Rust functions seamlessly:

// 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 query_database(sql: String) -> Result<Vec<Row>, String> {
    let db = get_database().await;
    db.query(&sql).await.map_err(|e| e.to_string())
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![read_file, query_database])
        .run(tauri::generate_context!())
        .expect("error running app");
}
Enter fullscreen mode Exit fullscreen mode
// Frontend — call Rust from JavaScript
import { invoke } from '@tauri-apps/api/core';

const content = await invoke<string>('read_file', { path: '/etc/hosts' });
const rows = await invoke<Row[]>('query_database', { sql: 'SELECT * FROM users' });
Enter fullscreen mode Exit fullscreen mode

Plugin API — v2's Game Changer

use tauri::plugin::{Builder, TauriPlugin};

pub fn init<R: Runtime>() -> TauriPlugin<R> {
    Builder::new("analytics")
        .invoke_handler(tauri::generate_handler![track_event, get_metrics])
        .setup(|app, api| {
            // Initialize on app start
            Ok(())
        })
        .build()
}

#[tauri::command]
async fn track_event(event: String, properties: serde_json::Value) -> Result<(), String> {
    // Your analytics logic
    Ok(())
}
Enter fullscreen mode Exit fullscreen mode

Mobile API — New in v2

import { Haptics } from '@tauri-apps/plugin-haptics';
import { Camera } from '@tauri-apps/plugin-camera';
import { Geolocation } from '@tauri-apps/plugin-geolocation';

// Haptic feedback on mobile
await Haptics.vibrate();

// Camera access
const photo = await Camera.getPhoto({ quality: 90 });

// Location
const pos = await Geolocation.getCurrentPosition();
Enter fullscreen mode Exit fullscreen mode

Quick Start

npm create tauri-app@latest -- --template react-ts
cd my-app
npm install && npm run tauri dev
Enter fullscreen mode Exit fullscreen mode

Why Teams Choose Tauri v2

A developer shared: "Our Electron app was 180MB. We rebuilt it in Tauri — same features, 4MB binary, half the RAM usage. Then Tauri v2 dropped and we shipped iOS and Android versions from the same codebase in a week."


Building cross-platform apps? Email spinov001@gmail.com or check my developer tools.

Tauri vs Electron vs Flutter — what's your choice for desktop apps?

Top comments (0)