Crates.io | mercure |
lib.rs | mercure |
version | 0.2.0 |
created_at | 2025-06-01 03:38:46.480298+00 |
updated_at | 2025-06-02 17:16:11.905937+00 |
description | A client implementation of the Mercure protocol |
homepage | |
repository | https://github.com/teohhanhui/mercure-rs |
max_upload_size | |
id | 1696855 |
size | 82,445 |
A client implementation of the Mercure protocol.
use std::error::Error;
use mercure::{HubUrl, PublisherJwt, TopicSelector};
use url::Url;
fn main() -> Result<(), Box<dyn Error>> {
let http_client = reqwest::Client::new();
let hub_url = HubUrl::try_from("https://localhost/.well-known/mercure".parse::<Url>()?)?;
let publisher_jwt = PublisherJwt::new(
&b"!ChangeThisMercureHubJWTSecretKey!".to_vec().into(),
vec![TopicSelector::Wildcard],
)?;
let client = mercure::Client::new(http_client, hub_url, publisher_jwt);
Ok(())
}
use std::error::Error;
use mercure::client::PublishUpdatePrivacy;
use mercure::{HubUrl, PublisherJwt, Topic, TopicSelector};
use url::Url;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let http_client = reqwest::Client::new();
let hub_url = HubUrl::try_from("https://localhost/.well-known/mercure".parse::<Url>()?)?;
let publisher_jwt = PublisherJwt::new(
&b"!ChangeThisMercureHubJWTSecretKey!".to_vec().into(),
vec![TopicSelector::Wildcard],
)?;
let client = mercure::Client::new(http_client, hub_url, publisher_jwt);
let topic = Topic::new("https://example.com/books/1".parse()?, vec![]);
let data = r#"{"isbn":"9780735218789"}"#;
let privacy = PublishUpdatePrivacy::Public;
client.publish_update(topic, Some(&data), privacy).await?;
Ok(())
}
use std::error::Error;
use mercure::jwt::SubscriberJwtSecret;
use mercure::{SubscriberJwt, TopicSelector};
fn main() -> Result<(), Box<dyn Error>> {
let subscriber_jwt_secret =
SubscriberJwtSecret::from(b"!ChangeThisMercureHubJWTSecretKey!".to_vec());
let subscriber_jwt = SubscriberJwt::new(&subscriber_jwt_secret, None, vec![
TopicSelector::UriTemplate("https://example.com/users/1/books/{book_id}".try_into()?),
])?;
Ok(())
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.