#channel #phoenix #serde-json

phyllo

Websocket-based client for Phoenix channels

4 releases (2 breaking)

0.3.0 Jul 28, 2022
0.2.0 Jul 8, 2022
0.1.1 Jul 7, 2022
0.1.0 Jul 7, 2022

#260 in WebSocket

Download history 97/week @ 2024-11-15 141/week @ 2024-11-22 193/week @ 2024-11-29 184/week @ 2024-12-06 179/week @ 2024-12-13 89/week @ 2024-12-20 68/week @ 2024-12-27 162/week @ 2025-01-03 268/week @ 2025-01-10 197/week @ 2025-01-17 178/week @ 2025-01-24 228/week @ 2025-01-31 263/week @ 2025-02-07 163/week @ 2025-02-14 265/week @ 2025-02-21 163/week @ 2025-02-28

925 downloads per month
Used in 2 crates

MIT/Apache

64KB
1.5K SLoC

phyllo

Phoenix channels in Rust. This crate uses the Actor model to provide Socket and Channel abstractions for connecting to, receiving and sending messages in a topical fashion. The overall structure is based on the reference JavaScript client.

Example

Warning: the results returned may include NSFW links or comments.

use serde_json::Value;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // The socket is generic over a Topic.
    let mut socket = SocketBuilder::new(Url::parse("wss://furbooru.org/socket/websocket")?)
        .build::<String>()
        .await;

    // Each channel is generic over an Event and Payload type.
    // For simplicity we use serde_json::Value, but in your own code you should deserialize
    // to something strongly-typed.
    let (_channel, mut subscription) = socket
        .channel::<String, Value, Value>(ChannelBuilder::new("firehose".to_string()))
        .await?;

    loop {
        let v = subscription.recv().await?;
        println!("{:?}", v);
    }
}

Features

TLS is not enabled by default. Enable either of the following for TLS support:

License: MIT OR Apache-2.0

Dependencies

~8–19MB
~263K SLoC