Expand description
§Firebase Functions Port (Rust)
§Introduction
The functions module provides a Rust port of the Firebase Cloud Functions (client) SDK so
applications can invoke HTTPS callable backends from native or WASM targets. The goal is to mirror
the modular JavaScript API (@firebase/functions) while using idiomatic Rust primitives.
§Porting status
- functions 25%
[### ]
(Estimated after landing the callable transport, context headers, and persistence plumbing on October 20th, 2025.)
§Quick Start Example
use firebase_rs_sdk::app::initialize_app;
use firebase_rs_sdk::app::{FirebaseAppSettings, FirebaseOptions};
use firebase_rs_sdk::functions::{get_functions, register_functions_component};
use serde_json::{json, Value as JsonValue};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
register_functions_component();
let app = initialize_app(
FirebaseOptions {
project_id: Some("demo-project".into()),
..Default::default()
},
Some(FirebaseAppSettings::default()),
)
.await?;
let functions = get_functions(Some(app.clone()), None).await?;
let callable = functions
.https_callable::<JsonValue, JsonValue>("helloWorld")?;
let response = callable
.call_async(&json!({ "message": "hi" }))
.await?;
println!("response: {response:?}");
Ok(())
}Use your platform’s async runtime to drive the main future (for example #[tokio::main] on
native targets or wasm_bindgen_futures::spawn_local on wasm32-unknown-unknown).
§Implemented
- Component registration so
Functionsinstances can be resolved from aFirebaseAppcontainer. - Native HTTPS callable transport backed by async
reqwest::Client, exposed through an async transport layer. - Public callable API is async-only so the module works seamlessly on native and WASM targets.
- Error code mapping aligned with the JS SDK (
packages/functions/src/error.ts) including backendstatustranslation and message propagation. - Custom-domain targeting (including emulator-style origins) by interpreting the instance
identifier passed to
get_functions. - Unit test (
https_callable_invokes_backend) that validates request/response wiring against an HTTP mock server (skips automatically when sockets are unavailable). - Context provider that pulls Auth and App Check credentials from the component system and injects
the appropriate
Authorization/X-Firebase-AppCheckheaders on outgoing callable requests. - WASM transport that issues callable requests through
fetch, mirrors native timeout semantics withAbortController, and reuses shared error mapping. - Automatic FCM token lookup so callable requests include the
Firebase-Instance-ID-Tokenheader when the Messaging component is configured and a cached (or freshly resolved) token is available.
§Still to do
- Serializer parity for Firestore Timestamp, GeoPoint, and other special values used by callable
payloads (
packages/functions/src/serializer.ts). - Emulator helpers (
connectFunctionsEmulator) and environment detection to configure the base origin (packages/functions/src/service.ts). - Streaming callable support (
httpsCallable().stream) that handles server-sent events. - Public helpers like
httpsCallableFromURLand region selection utilities frompackages/functions/src/api.ts. - Comprehensive error detail decoding (custom
detailspayload) and cancellation handling. - Broader test coverage mirroring
packages/functions/src/callable.test.ts. - Restore Firebase Messaging token forwarding on WASM once the messaging module exposes a wasm-web implementation.
§Next steps - Detailed completion plan
- Serializer parity & URL utilities
- Port the callable serializer helpers (Firestore timestamps, GeoPoints) and add helpers such as
https_callable_from_urlandconnect_functions_emulatorfor full API coverage.
- Port the callable serializer helpers (Firestore timestamps, GeoPoints) and add helpers such as
- Wasm validation & tooling
- Stand up
wasm-bindgen-testcoverage to verify the fetch transport, timeout handling, and header propagation in a browser-like environment. - Document the crate features (
wasm-web) and any required Service Worker setup in the README example section.
- Stand up
- Advanced error handling
- Surface backend
detailspayloads and cancellation hooks so callers can differentiate retryable vs. fatal failures, matchingpackages/functions/src/error.tssemantics.
- Surface backend
- Async adoption sweep
- Audit the workspace for callers of
get_functionsandCallableFunction::call_async, updating each site to await the async APIs and adjusting examples/docs where necessary. - Re-run the smoke scripts (
scripts/smoke.sh/.bat) to confirm both native and wasm builds stay green after the sweep.
- Audit the workspace for callers of
Modules§
Structs§
- Callable
Function - Callable Cloud Function handle that can be invoked with typed payloads.
- Functions
- Client entry point for invoking HTTPS callable Cloud Functions.
Functions§
- get_
functions - Fetches (or lazily creates) a
Functionsclient for the given Firebase app. - register_
functions_ component - Registers the Functions component with the global app container.