diff --git a/README.md b/README.md index 00cdf04..75c0360 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ const url$ = getDownloadURL(ref); - [Authentication](docs/auth.md) - [Storage](docs/storage.md) - [Realtime Database](docs/database.md) +- [Cloud Functions](docs/functions.md) ## Examples diff --git a/docs/functions.md b/docs/functions.md new file mode 100644 index 0000000..438d12a --- /dev/null +++ b/docs/functions.md @@ -0,0 +1,34 @@ +# RxFire Cloud Functions + +## Callable Functions Observables + +### `httpsCallable()` + +The `httpsCallable()` function returns an observable that calls a [callable function](https://firebase.google.com/docs/functions/callable), then emits the data returned from that function. + +| | | +| --------------- | ------------------------------------------------------------------------ | +| **function** | `httpsCallable()` | +| **params** | `functions: Functions`, `name: string`, `options?: HttpsCallableOptions` | +| **import path** | `rxfire/functions` | +| **return** | `(data: T) => Observable` | + +#### TypeScript Example + +```ts +import { httpsCallable } from "rxfire/functions"; +import { initializeApp } from "firebase/app"; +import { getFunctions } from "firebase/functions"; + +// Set up Firebase +const app = initializeApp({ + /* config */ +}); +const functions = getFunctions(app); + +// Assume an `uppercaser` function is deployed +const capitalizedText$ = httpsCallable(functions, "uppercaser")("hello world"); +capitalizedText$.subscribe((text) => { + console.log(text); +}); // logs "HELLO WORLD" +```