#websocket-server #leptos #server #signal #server-client #websocket-client

nightly leptos_ws

Leptos WS is a Websocket for the Leptos framework to support updates coordinated from the Server

6 releases

new 0.7.0 Dec 9, 2024
0.7.0-rc1 Nov 16, 2024
0.7.0-beta5 Sep 28, 2024
0.7.0-beta2 Aug 31, 2024

#329 in WebSocket

Download history 255/week @ 2024-08-26 207/week @ 2024-09-02 46/week @ 2024-09-16 161/week @ 2024-09-23 33/week @ 2024-09-30 9/week @ 2024-10-07 10/week @ 2024-10-14 88/week @ 2024-11-11 32/week @ 2024-11-18

120 downloads per month

MIT license

40KB
754 lines

Leptos Websocket

Crates.io docs.rs

Leptos Websocket provides server signals for Leptos, keeping them in sync with the server through WebSockets. This enables real-time updates on the UI controlled by the server.

Features

  • Server Signals: Read-only signals on the client side, writable by the server.
  • Real-time Updates: Changes to signals are sent through WebSockets as JSON patches.
  • Framework Integration: Supports integration with the Axum web framework.

Installation

Add the following to your Cargo.toml:

[dependencies]
leptos_ws = "0.7.0-rc1"
serde = { version = "1.0", features = ["derive"] }

[features]
ssr = ["leptos_ws/ssr", "leptos_ws/axum"]

Usage

Client-side

use leptos::prelude::*;
use serde::{Deserialize, Serialize};

#[component]
pub fn App() -> impl IntoView {
    // Connect to WebSocket
    leptos_ws::provide_websocket("http://localhost:3000/ws");

    // Create server signal
    let count = leptos_ws::ServerSignal::new("count".to_string(), 0 as i32).unwrap();

    view! {
        <h1>"Count: " {move || count.get().to_string()}</h1>
    }
}

Server-side (Axum)

Server-side implementation requires additional setup. Refer to the example for detailed examples.

Feature Flags

  • ssr: Enable server-side rendering support.
  • axum: Enable integration with the Axum web framework.

Documentation

For more detailed information, check out the API documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependencies

~23–36MB
~577K SLoC