#notifications

fcm_http1

An API to talk to FCM (Firebase Cloud Messaging) in Rust

3 releases

0.1.2 Jul 27, 2024
0.1.1 Jul 26, 2024
0.1.0 Jul 26, 2024

#43 in #notification

Download history 269/week @ 2024-07-22 67/week @ 2024-07-29 40/week @ 2024-09-02 27/week @ 2024-09-16 5/week @ 2024-09-23 2/week @ 2024-09-30

59 downloads per month

MIT license

43KB
779 lines

fcm

Cargo tests Coveralls Crates.io Version Crates.io Downloads Crates.io License

Matrix chat

Requirements

Needs a Tokio executor version 1.0 or later and Rust compiler version 1.45.0 or later.

Examples

Check out the examples directory for a simple sender.


lib.rs:

fcm

A client for asynchronous sending of Firebase Cloud Messages, or Push Notifications.

Examples:

To send out a FCM Message with some custom data:

let client = fcm_http1::Client::new();

let mut map = HashMap::new();
map.insert("message", "Howdy!");

let mut builder = fcm_http1::MessageBuilder::new("<FCM API Key>", "<registration id>");
builder.data(&map);

let response = client.send(builder.finalize()).await?;
println!("Sent: {:?}", response);

To send a message using FCM Notifications, we first build the notification:

let mut builder = fcm_http1::NotificationBuilder::new();
builder.title("Hey!");
builder.body("Do you want to catch up later?");
let notification = builder.finalize();

And then set it in the message, before sending it:

let client = fcm_http1::Client::new();

let mut notification_builder = fcm_http1::NotificationBuilder::new();
notification_builder.title("Hey!");
notification_builder.body("Do you want to catch up later?");

let notification = notification_builder.finalize();
let mut message_builder = fcm_http1::MessageBuilder::new("<FCM API Key>", "<registration id>");
message_builder.notification(notification);

let response = client.send(message_builder.finalize()).await?;
println!("Sent: {:?}", response);

Dependencies

~5–20MB
~300K SLoC