active_sse 0.1.0

Activeledger Rust SDK for SSE - Server Sent Events
Documentation
# Activeledger SSE Helper This crate is a helper crate that handles the setup and configuration of Server Sent Events (Eventsource) calls to Activeledger. ## Usage To create a new ActiveSSE instance you need to create a config first. This defines various data needed ActiveSSE to connect to the correct Activeledger API endpoint. The config types are Activity and Event. These are created simply by calling `let mut config = Config::activity("http://base-url");` `let mut config = Config::event("http://base-url");` Once you have created the initial config instance you can pass in the optional data via function calls. Once configured, use it to create a new instance of ActiveSSE: `let sse = ActiveSSE::new(config);` When you are ready, call the subscribe function: `let receiver = sse.subscribe();` Then you can listen for activity or events ``` # use active_sse::{Config, ActiveSSE}; # let config = Config::activity("http://localhost:5260"); # let listener = ActiveSSE::new(config); # let receiver = listener.subscribe().unwrap(); // Note that this will only return once println!("{:?}", receiver.recv().unwrap()); ``` This returns a [`receiever`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Receiver.html) which makes up part of Rust's channel type. You can retrieve messages to it by calling [`recv`](https://doc.rust-lang.org/nightly/std/sync/mpsc/struct.Receiver.html#method.recv) This will only be triggered once, but can be put into a loop to listen for multiple events. ### A complete setup might look like this ``` use active_sse::{Config, ActiveSSE}; let mut config = Config::activity("http://localhost:5260"); config.set_stream_id("Stream id").unwrap(); let listener = ActiveSSE::new(config); let receiver = listener.subscribe().unwrap(); // Note that this will only return once println!("{:?}", receiver.recv().unwrap()); ``` ## Additional Activeledger crates Adhearing to the Rust mentality of keeping things small we have created other crates that can be used in conjunction with this one to add additional functionality. These crates are: * [activeledger](https://github.com/activeledger/SDK-Rust) - For handling connections and keys ([Crate](https://crates.io/crates/activeledger)) * [active_txbuilder](https://github.com/activeledger/SDK-Rust-TxBuilder) - To build transactions without worrying about the JSON. ([Crate](https://crates.io/crates/active_tx)) ## Links [Activeledger](https://activeledger.io) [Activeledger Developers portal](https://developers.activeledger.io) [Activeledger on GitHub](https://github.com/activeledger/activeledger) [Activeledger on NPM](https://www.npmjs.com/package/@activeledger/activeledger) [This SDK on GitHub](https://github.com/activeledger/SDK-Rust) [Report Issues](https://github.com/activeledger/SDK-Rust/issues)