mirror of
https://github.com/hanzoai/firebase-js-sdk.git
synced 2026-09-24 16:59:10 +00:00
The new .stream() API allows the client to consume streaming responses from the WIP streaming callable functions in Firebase Functions Node.js SDK.
When client makes a request to the callable function w/ header Accept: text/event-stream, the callable function responds with response chunks in Server-Sent Event format.
The sdk changes here abstracts over the wire-protocol by parsing the response chunks and returning an instance of a AsyncIterable to consume to data:
import { getFunctions, httpsCallable } from "firebase/functions";
const functions = getFunctions();
const generateText = httpsCallable(functions, 'generateText');
const resp = await generateText.stream(
{ text: 'What is your favorite Firebase service and why?' },
{ signal: AbortSignal.timeout(60_000) },
);
try {
for await (const message of resp.stream) {
console.log(message); // prints "foo", "bar"
}
console.log(await resp.data) // prints "foo bar"
} catch (e) {
// FirebaseError(code='cancelled', message='Request was cancelled.');
console.error(e)
}
34 lines
1.2 KiB
Markdown
34 lines
1.2 KiB
Markdown
Project: /docs/reference/js/_project.yaml
|
|
Book: /docs/reference/_book.yaml
|
|
page_type: reference
|
|
|
|
{% comment %}
|
|
DO NOT EDIT THIS FILE!
|
|
This is generated by the JS SDK team, and any local changes will be
|
|
overwritten. Changes should be made in the source code at
|
|
https://github.com/firebase/firebase-js-sdk
|
|
{% endcomment %}
|
|
|
|
# HttpsCallable interface
|
|
A reference to a "callable" HTTP trigger in Cloud Functions.
|
|
|
|
<b>Signature:</b>
|
|
|
|
```typescript
|
|
export interface HttpsCallable<RequestData = unknown, ResponseData = unknown, StreamData = unknown>
|
|
```
|
|
|
|
## Properties
|
|
|
|
| Property | Type | Description |
|
|
| --- | --- | --- |
|
|
| [stream](./functions.httpscallable.md#httpscallablestream) | (data?: RequestData \| null, options?: [HttpsCallableStreamOptions](./functions.httpscallablestreamoptions.md#httpscallablestreamoptions_interface)<!-- -->) => Promise<[HttpsCallableStreamResult](./functions.httpscallablestreamresult.md#httpscallablestreamresult_interface)<!-- --><ResponseData, StreamData>> | |
|
|
|
|
## HttpsCallable.stream
|
|
|
|
<b>Signature:</b>
|
|
|
|
```typescript
|
|
stream: (data?: RequestData | null, options?: HttpsCallableStreamOptions) => Promise<HttpsCallableStreamResult<ResponseData, StreamData>>;
|
|
```
|