https://github.com/TimTom2016/leptos_ws
Leptos Ws is a Websocket for the Leptos framework to support updates coordinated from the Server
https://github.com/TimTom2016/leptos_ws
Last synced: 4 months ago
JSON representation
Leptos Ws is a Websocket for the Leptos framework to support updates coordinated from the Server
- Host: GitHub
- URL: https://github.com/TimTom2016/leptos_ws
- Owner: TimTom2016
- License: mit
- Created: 2024-07-16T07:29:36.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-03-02T16:12:01.000Z (4 months ago)
- Last Synced: 2025-03-02T16:39:10.903Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 171 KB
- Stars: 19
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-leptos - leptos_ws
README
# Leptos Websocket
[](https://crates.io/crates/leptos_ws)
[](https://docs.rs/leptos_ws/)Leptos Websocket provides server signals for [Leptos](https://github.com/leptos-rs/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](https://docs.rs/json-patch/latest/json_patch/struct.Patch.html).
- **Framework Integration**: Supports integration with the [Axum](https://github.com/tokio-rs/axum) web framework.## Installation
Add the following to your `Cargo.toml`:
```toml
[dependencies]
leptos_ws = "0.7.7"
serde = { version = "1.0", features = ["derive"] }[features]
ssr = ["leptos_ws/ssr", "leptos_ws/axum"]
```## Usage
### Client-side
```rust
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! {
"Count: " {move || count.get().to_string()}
}
}
```### 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](https://docs.rs/leptos_ws/).
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.