A very simple library to implement the Firebase real-time database in your code with the best performance
Add this to your Cargo.toml
:
toml
[dependencies]
firerust = { version = "1" }
Import firerust
rust
use firerust::FirebaseClient;
Initialize a Firebase client without auth
rust
FirebaseClient::new("https:///<DATABASE_NAME>.firebaseio.com/")?;
Initialize a Firebase client with auth
rust
let mut client = FirebaseClient::new("https:///<DATABASE_NAME>.firebaseio.com/")?;
client.auth("<ID_TOKEN>");
A basic example of data fetch: ```rust use firerust::FirebaseClient; use serde_json::Value;
let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?; let reference = client.reference("/");
println!("{:?}", reference.get::
A basic example of data set: ```rust use firerust::FirebaseClient;
let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?; let reference = client.reference("/");
reference.set(serde_json::json!({ "message": "Setting data" }))?; ```
A basic example of data update: ```rust use firerust::FirebaseClient;
let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?; let reference = client.reference("/");
reference.update(serde_json::json!({ "message": "Updating data" }))?; ```
A basic example of data deletion: ```rust use firerust::FirebaseClient;
let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?; let reference = client.reference("/");
reference.delete()?; ```
A snapshot event example: ```rust use firerust::FirebaseClient; use serde_json::Value;
let client = FirebaseClient::new("https://docs-examples.firebaseio.com/")?; let reference = client.reference("/");
reference.on_snapshot(| data: Value | { println!("{:?}", data);
Ok(())
})?; ```