#push-notifications #firebase #fcm #api-bindings #send-notifications #async #rust

fcm-rs

A Rust crate for easy interaction with Firebase Cloud Messaging API (V1)

2 unstable releases

0.2.0 Jul 20, 2024
0.1.0 Jun 12, 2024

#4 in #fcm

Download history 26/week @ 2024-07-22 6/week @ 2024-07-29 19/week @ 2024-08-19 8/week @ 2024-08-26 32/week @ 2024-09-02 56/week @ 2024-09-09 73/week @ 2024-09-16 29/week @ 2024-09-23 29/week @ 2024-09-30 56/week @ 2024-10-07 37/week @ 2024-10-14 6/week @ 2024-10-21 9/week @ 2024-10-28 14/week @ 2024-11-04

74 downloads per month

MIT license

13KB
138 lines

Firebase Cloud Messaging API v1 Rust Crate

This Rust crate provides a convenient way to send notifications using Firebase Cloud Messaging (FCM) API v1. It leverages async/await for asynchronous operations and supports loading service account credentials from a JSON file.

Installation

Add this crate to your Cargo.toml:

[dependencies]
fcm-rs = "0.2.0"

Usage

Below is an example of how to use this crate to send a notification:

use fcm_rs::{ client::FcmClient, models::{ Message, Notification } };

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let service_account_path = "path/to/service_account";

    // Create a new FCM client
    let client = FcmClient::new(service_account_path).await?;

    // Define the message with the target device token and notification details
    let message = Message {
        token: Some("your_device_token".to_string()),
        notification: Some(Notification {
            title: Some("Hello from Rust!".to_string()),
            body: Some("This is a test notification.".to_string()),
        }),
        data: None,
    };

    // Send the message and handle the response
    let response = client.send(message).await?;
    println!("FCM response: {:?}", response);

    Ok(())
}

Contribution

Contributions are welcome! Feel free to submit issues or pull requests.

Contact

For any queries or suggestions, please open an issue on the GitHub repository.

Dependencies

~13–25MB
~361K SLoC