DEV Community

Alex Spinov
Alex Spinov

Posted on

Leptos Has a Free API That Builds Full-Stack Web Apps in Rust With Fine-Grained Reactivity

Leptos is a Rust framework for building web apps. Compiles to WebAssembly for the client, native Rust for the server. Fine-grained reactivity like SolidJS, but in Rust.

Quick Start

cargo install cargo-leptos
cargo leptos new --git leptos-rs/start
cd my-app && cargo leptos watch
Enter fullscreen mode Exit fullscreen mode

Components

use leptos::*;

#[component]
fn Counter() -> impl IntoView {
    let (count, set_count) = create_signal(0);

    view! {
        <button on:click=move |_| set_count.update(|n| *n += 1)>
            "Count: " {count}
        </button>
    }
}
Enter fullscreen mode Exit fullscreen mode

Server Functions

#[server(GetPosts)]
pub async fn get_posts() -> Result<Vec<Post>, ServerFnError> {
    let posts = db::get_all_posts().await?;
    Ok(posts)
}

#[component]
fn PostList() -> impl IntoView {
    let posts = create_resource(|| (), |_| get_posts());

    view! {
        <Suspense fallback=move || view! { <p>"Loading..."</p> }>
            {move || posts.get().map(|data| view! {
                <For each=move || data.clone() key=|p| p.id let:post>
                    <p>{post.title}</p>
                </For>
            })}
        </Suspense>
    }
}
Enter fullscreen mode Exit fullscreen mode

Why Rust for Web?

Leptos (Rust) Next.js (JS)
WASM bundle ~200KB ~300KB+
Runtime perf Fastest Good
Type safety Compiler-enforced TypeScript
Memory safety Guaranteed GC

The Bottom Line

Leptos is for Rust developers who want full-stack web. Compiler-level safety, WebAssembly performance, SolidJS-style reactivity.


Need to automate data collection or build custom scrapers? Check out my Apify actors for ready-made tools, or email spinov001@gmail.com for custom solutions.

Top comments (0)