Skip to content

Commit 6167f9b

Browse files
authored
Merge pull request #267606 from ggailey777/madhura
[Functions] New HTTP streams for node.js
2 parents a401043 + eb57b33 commit 6167f9b

File tree

2 files changed

+91
-6
lines changed

2 files changed

+91
-6
lines changed

articles/azure-functions/functions-bindings-http-webhook-trigger.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ This example reads the body of a POST request, as a `String`, and uses it to bui
189189

190190
#### Read parameter from a route
191191

192-
This example reads a mandatory parameter, named `id`, and an optional parameter `name` from the route path, and uses them to build a JSON document returned to the client, with content type `application/json`. T
192+
This example reads a mandatory parameter, named `id`, and an optional parameter `name` from the route path, and uses them to build a JSON document returned to the client, with content type `application/json`.
193193

194194
```java
195195
@FunctionName("TriggerStringRoute")
@@ -1004,6 +1004,12 @@ When you use route parameters, an `invoke_URL_template` is automatically created
10041004

10051005
You can programmatically access the `invoke_URL_template` by using the Azure Resource Manager APIs for [List Functions](/rest/api/appservice/webapps/listfunctions) or [Get Function](/rest/api/appservice/webapps/getfunction).
10061006

1007+
::: zone pivot="programming-language-javascript,programming-language-typescript"
1008+
### HTTP streams (preview)
1009+
1010+
You can now stream requests to and responses from your HTTP endpoint in Node.js v4 function apps. For more information, see [HTTP streams](functions-reference-node.md?pivots=nodejs-model-v4#http-streams-preview).
1011+
::: zone-end
1012+
10071013
### Working with client identities
10081014

10091015
If your function app is using [App Service Authentication / Authorization](../app-service/overview-authentication-authorization.md), you can view information about authenticated clients from your code. This information is available as [request headers injected by the platform](../app-service/configure-authentication-user-identities.md#access-user-claims-in-app-code).

articles/azure-functions/functions-reference-node.md

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Node.js developer reference for Azure Functions
33
description: Understand how to develop functions by using Node.js.
44
ms.assetid: 45dedd78-3ff9-411f-bb4b-16d29a11384c
55
ms.topic: conceptual
6-
ms.date: 04/17/2023
6+
ms.date: 02/28/2024
77
ms.devlang: javascript
88
# ms.devlang: javascript, typescript
99
ms.custom: devx-track-js, vscode-azure-extension-update-not-needed
@@ -33,8 +33,8 @@ The following table shows each version of the Node.js programming model along wi
3333
| ---- | ---- | --- | --- | --- |
3434
| 4.x | GA | 4.25+ | 20.x (Preview), 18.x | Supports a flexible file structure and code-centric approach to triggers and bindings. |
3535
| 3.x | GA | 4.x | 20.x (Preview), 18.x, 16.x, 14.x | Requires a specific file structure with your triggers and bindings declared in a "function.json" file |
36-
| 2.x | GA (EOL) | 3.x | 14.x, 12.x, 10.x | Reached end of life (EOL) on December 13, 2022. See [Functions Versions](./functions-versions.md) for more info. |
37-
| 1.x | GA (EOL) | 2.x | 10.x, 8.x | Reached end of life (EOL) on December 13, 2022. See [Functions Versions](./functions-versions.md) for more info. |
36+
| 2.x | n/a | 3.x | 14.x, 12.x, 10.x | Reached end of support on December 13, 2022. See [Functions Versions](./functions-versions.md) for more info. |
37+
| 1.x | n/a | 2.x | 10.x, 8.x | Reached end of support on December 13, 2022. See [Functions Versions](./functions-versions.md) for more info. |
3838

3939
## Folder structure
4040

@@ -730,7 +730,7 @@ app.storageQueue('copyBlob1', {
730730
731731
### Generic inputs and outputs
732732
733-
The `app`, `trigger`, `input`, and `output` objects exported by the `@azure/functions` module provide type-specific methods for most types. For all the types that aren't supported, a `generic` method has been provided to allow you to manually specify the configuration. The `generic` method can also be used if you want to change the default settings provided by a type-specific method.
733+
The `app`, `trigger`, `input`, and `output` objects exported by the `@azure/functions` module provide type-specific methods for most types. For all the types that aren't supported, a `generic` method is provided to allow you to manually specify the configuration. The `generic` method can also be used if you want to change the default settings provided by a type-specific method.
734734

735735
The following example is a simple HTTP triggered function using generic methods instead of type-specific methods.
736736

@@ -1222,7 +1222,7 @@ The `HttpRequest` object has the following properties:
12221222
| **`params`** | `Record<string, string>` | Route parameter keys and values. |
12231223
| **`user`** | `HttpRequestUser | null` | Object representing logged-in user, either through Functions authentication, SWA Authentication, or null when no such user is logged in. |
12241224
| **`body`** | [`ReadableStream | null`](https://developer.mozilla.org/docs/Web/API/ReadableStream) | Body as a readable stream. |
1225-
| **`bodyUsed`** | `boolean` | A boolean indicating if the body has been read from already. |
1225+
| **`bodyUsed`** | `boolean` | A boolean indicating if the body is already read. |
12261226
12271227
In order to access a request or response's body, the following methods can be used:
12281228
@@ -1422,6 +1422,85 @@ The response can be set in several ways:
14221422
14231423
::: zone-end
14241424
1425+
## HTTP streams (preview)
1426+
1427+
HTTP streams is a feature that makes it easier to process large data, stream OpenAI responses, deliver dynamic content, and support other core HTTP scenarios. It lets you stream requests to and responses from HTTP endpoints in your Node.js function app. Use HTTP streams in scenarios where your app requires real-time exchange and interaction between client and server over HTTP. You can also use HTTP streams to get the best performance and reliability for your apps when using HTTP.
1428+
1429+
HTTP streams is currently in preview.
1430+
1431+
::: zone pivot="nodejs-model-v3"
1432+
>[!IMPORTANT]
1433+
>HTTP streams aren't supported in the v3 model. [Upgrade to the v4 model](./functions-node-upgrade-v4.md) to use the HTTP streaming feature.
1434+
::: zone-end
1435+
::: zone pivot="nodejs-model-v4"
1436+
The existing `HttpRequest` and `HttpResponse` types in programming model v4 already support various ways of handling the message body, including as a stream.
1437+
1438+
### Prerequisites
1439+
- The [`@azure/functions` npm package](https://www.npmjs.com/package/@azure/functions) version 4.3.0 or later.
1440+
- [Azure Functions runtime](./functions-versions.md) version 4.28 or later.
1441+
- [Azure Functions Core Tools](./functions-run-local.md) version 4.0.5530 or a later version, which contains the correct runtime version.
1442+
1443+
### Enable streams
1444+
1445+
Use these steps to enable HTTP streams in your function app in Azure and in your local projects:
1446+
1447+
1. If you plan to stream large amounts of data, modify the [`FUNCTIONS_REQUEST_BODY_SIZE_LIMIT`](./functions-app-settings.md#functions_request_body_size_limit) setting in Azure. The default maximum body size allowed is `104857600`, which limits your requests to a size of ~100 MB.
1448+
1449+
1. For local development, also add `FUNCTIONS_REQUEST_BODY_SIZE_LIMIT` to the [local.settings.json file](./functions-develop-local.md#local-settings-file).
1450+
1451+
1. Add the following code to your app in any file included by your [main field](./functions-reference-node.md#registering-a-function).
1452+
1453+
#### [JavaScript](#tab/javascript)
1454+
1455+
```javascript
1456+
const { app } = require('@azure/functions');
1457+
1458+
app.setup({ enableHttpStream: true });
1459+
```
1460+
1461+
#### [TypeScript](#tab/typescript)
1462+
1463+
```typescript
1464+
import { app } from '@azure/functions';
1465+
1466+
app.setup({ enableHttpStream: true });
1467+
```
1468+
1469+
---
1470+
1471+
### Stream examples
1472+
1473+
This example shows an HTTP triggered function that receives data via an HTTP POST request, and the function streams this data to a specified output file:
1474+
1475+
#### [JavaScript](#tab/javascript)
1476+
1477+
:::code language="javascript" source="~/azure-functions-nodejs-v4/js/src/functions/httpTriggerStreamRequest.js" :::
1478+
1479+
#### [TypeScript](#tab/typescript)
1480+
1481+
:::code language="typescript" source="~/azure-functions-nodejs-v4/ts/src/functions/httpTriggerStreamRequest.ts" :::
1482+
1483+
---
1484+
1485+
This example shows an HTTP triggered function that streams a file's content as the response to incoming HTTP GET requests:
1486+
1487+
#### [JavaScript](#tab/javascript)
1488+
1489+
:::code language="javascript" source="~/azure-functions-nodejs-v4/js/src/functions/httpTriggerStreamResponse.js" :::
1490+
1491+
#### [TypeScript](#tab/typescript)
1492+
1493+
:::code language="typescript" source="~/azure-functions-nodejs-v4/ts/src/functions/httpTriggerStreamResponse.ts" :::
1494+
1495+
---
1496+
1497+
### Stream considerations
1498+
1499+
+ The `request.params` object isn't supported when using HTTP streams during preview. Refer to this [GitHub issue](https://github.com/Azure/azure-functions-nodejs-library/issues/229) for more information and suggested workaround.
1500+
1501+
+ Use `request.body` to obtain the maximum benefit from using streams. You can still continue to use methods like `request.text()`, which always return the body as a string.
1502+
::: zone-end
1503+
14251504
## Hooks
14261505
14271506
::: zone pivot="nodejs-model-v3"

0 commit comments

Comments
 (0)