Skip to content

Commit 167352d

Browse files
Merge pull request #290390 from cgillum/durable-http-updates
Update Durable HTTP features documentation
2 parents ad0a354 + 4a35f13 commit 167352d

File tree

1 file changed

+72
-14
lines changed

1 file changed

+72
-14
lines changed

articles/azure-functions/durable/durable-functions-http-features.md

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: HTTP features in Durable Functions - Azure Functions
33
description: Learn about the integrated HTTP features in the Durable Functions extension for Azure Functions.
44
author: cgillum
55
ms.topic: conceptual
6-
ms.date: 05/10/2022
6+
ms.date: 11/11/2024
77
ms.author: azfuncdf
88
ms.devlang: csharp
99
# ms.devlang: csharp, java, javascript, powershell, python
@@ -38,10 +38,39 @@ See the [HTTP APIs article](durable-functions-http-api.md) for a full descriptio
3838

3939
The [orchestration client binding](durable-functions-bindings.md#orchestration-client) exposes APIs that can generate convenient HTTP response payloads. For example, it can create a response containing links to management APIs for a specific orchestration instance. The following examples show an HTTP-trigger function that demonstrates how to use this API for a new orchestration instance:
4040

41-
# [C#](#tab/csharp)
41+
# [C# (InProc)](#tab/csharp-inproc)
4242

4343
[!code-csharp[Main](~/samples-durable-functions/samples/precompiled/HttpStart.cs)]
4444

45+
# [C# (Isolated)](#tab/csharp-isolated)
46+
47+
```csharp
48+
/// <summary>
49+
/// HTTP-triggered function that starts the <see cref="HelloCitiesUntyped"/> orchestration.
50+
/// </summary>
51+
/// <param name="req">The HTTP request that was used to trigger this function.</param>
52+
/// <param name="client">The DurableTask client that is used to start and manage orchestration instances.</param>
53+
/// <param name="executionContext">The Azure Functions execution context, which is available to all function types.</param>
54+
/// <returns>Returns an HTTP response with more information about the started orchestration instance.</returns>
55+
[Function(nameof(StartHelloCitiesUntyped))]
56+
public static async Task<HttpResponseData> StartHelloCitiesUntyped(
57+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
58+
[DurableClient] DurableTaskClient client,
59+
FunctionContext executionContext)
60+
{
61+
ILogger logger = executionContext.GetLogger(nameof(StartHelloCitiesUntyped));
62+
63+
string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(nameof(HelloCitiesUntyped));
64+
logger.LogInformation("Created new orchestration with instance ID = {instanceId}", instanceId);
65+
66+
// Returns an HTTP response with a payload that includes links to built-in HTTP management payloads
67+
return client.CreateCheckStatusResponse(req, instanceId);
68+
}
69+
```
70+
71+
> [!NOTE]
72+
> The `CreateCheckStatusResponse` and related APIs currently only support `HttpRequestData` and `HttpResponseData` types when working with HTTP-triggered functions. ASP.NET-defined types are not currently supported.
73+
4574
# [JavaScript](#tab/javascript)
4675

4776
**index.js**
@@ -222,10 +251,10 @@ Starting with Durable Functions 2.0, orchestrations can natively consume HTTP AP
222251

223252
The following example code shows an orchestrator function making an outbound HTTP request:
224253

225-
# [C#](#tab/csharp)
254+
# [C# (InProc)](#tab/csharp-inproc)
226255

227256
```csharp
228-
[FunctionName("CheckSiteAvailable")]
257+
[FunctionName(nameof(CheckSiteAvailable))]
229258
public static async Task CheckSiteAvailable(
230259
[OrchestrationTrigger] IDurableOrchestrationContext context)
231260
{
@@ -242,6 +271,36 @@ public static async Task CheckSiteAvailable(
242271
}
243272
```
244273

274+
> [!NOTE]
275+
> You might wonder why this feature uses the **DurableHttpRequest** and **DurableHttpResponse** types instead of the built-in .NET **HttpRequestMessage** and **HttpResponseMessage** types.
276+
>
277+
> This design choice is intentional. The primary reason is that custom types help ensure users don't make incorrect assumptions about the supported behaviors of the internal HTTP client. Types specific to Durable Functions also make it possible to simplify API design. They also can more easily make available special features like [managed identity integration](#managed-identities) and the [polling consumer pattern](#http-202-handling).
278+
279+
# [C# (Isolated)](#tab/csharp-isolated)
280+
281+
```csharp
282+
[Function(nameof(CheckSiteAvailable))]
283+
public static async Task CheckSiteAvailable(
284+
[OrchestrationTrigger] TaskOrchestrationContext context)
285+
{
286+
Uri url = context.GetInput<Uri>();
287+
288+
// Makes an HTTP GET request to the specified endpoint
289+
DurableHttpResponse response =
290+
await context.CallHttpAsync(HttpMethod.Get, url);
291+
292+
if (response.StatusCode >= HttpStatusCode.BadRequest)
293+
{
294+
// handling of error codes goes here
295+
}
296+
}
297+
```
298+
299+
> [!NOTE]
300+
> You might wonder why this feature uses the **DurableHttpRequest** and **DurableHttpResponse** types instead of the built-in .NET **HttpRequestMessage** and **HttpResponseMessage** types.
301+
>
302+
> This design choice is intentional. The primary reason is that custom types help ensure users don't make incorrect assumptions about the supported behaviors of the internal HTTP client. Types specific to Durable Functions also make it possible to simplify API design. They also can more easily make available special features that aren't part of the built-in framework types.
303+
245304
# [JavaScript](#tab/javascript)
246305

247306
```javascript
@@ -291,21 +350,21 @@ By using the "call HTTP" action, you can do the following actions in your orches
291350

292351
The ability to consume HTTP APIs directly from orchestrator functions is intended as a convenience for a certain set of common scenarios. You can implement all of these features yourself using activity functions. In many cases, activity functions might give you more flexibility.
293352

294-
### HTTP 202 handling
353+
### <a name="http-202-handling"></a>HTTP 202 handling (.NET in-process only)
295354

296355
The "call HTTP" API can automatically implement the client side of the polling consumer pattern. If a called API returns an HTTP 202 response with a Location header, the orchestrator function automatically polls the Location resource until receiving a response other than 202. This response will be the response returned to the orchestrator function code.
297356

298357
> [!NOTE]
299358
> 1. Orchestrator functions also natively support the server-side polling consumer pattern, as described in [Async operation tracking](#async-operation-tracking). This support means that orchestrations in one function app can easily coordinate the orchestrator functions in other function apps. This is similar to the [sub-orchestration](durable-functions-sub-orchestrations.md) concept, but with support for cross-app communication. This support is particularly useful for microservice-style app development.
300-
> 2. Due to a temporary limitation, the built-in HTTP polling pattern is not currently available in JavaScript/TypeScript and Python.
359+
> 2. The built-in HTTP polling pattern is currently available only in the .NET in-process host.
301360
302361
### Managed identities
303362

304363
Durable Functions natively supports calls to APIs that accept Microsoft Entra tokens for authorization. This support uses [Azure managed identities](../../active-directory/managed-identities-azure-resources/overview.md) to acquire these tokens.
305364

306365
The following code is an example of an orchestrator function. The function makes authenticated calls to restart a virtual machine by using the Azure Resource Manager [virtual machines REST API](/rest/api/compute/virtualmachines).
307366

308-
# [C#](#tab/csharp)
367+
# [C# (InProc)](#tab/csharp-inproc)
309368

310369
```csharp
311370
[FunctionName("RestartVm")]
@@ -331,6 +390,10 @@ public static async Task RunOrchestrator(
331390
}
332391
```
333392

393+
# [C# (Isolated)](#tab/csharp-isolated)
394+
395+
This feature isn't yet available in the .NET Isolated worker.
396+
334397
# [JavaScript](#tab/javascript)
335398

336399
```javascript
@@ -414,14 +477,9 @@ HTTP requests sent by orchestrator functions and their responses are [serialized
414477

415478
If any of these limitations might affect your use case, consider instead using activity functions and language-specific HTTP client libraries to make outbound HTTP calls.
416479

417-
> [!NOTE]
418-
> If you are a .NET developer, you might wonder why this feature uses the **DurableHttpRequest** and **DurableHttpResponse** types instead of the built-in .NET **HttpRequestMessage** and **HttpResponseMessage** types.
419-
>
420-
> This design choice is intentional. The primary reason is that custom types help ensure users don't make incorrect assumptions about the supported behaviors of the internal HTTP client. Types specific to Durable Functions also make it possible to simplify API design. They also can more easily make available special features like [managed identity integration](#managed-identities) and the [polling consumer pattern](#http-202-handling).
421-
422-
### Extensibility (.NET only)
480+
### <a name="extensibility"></a>Extensibility (.NET in-process only)
423481

424-
Customizing the behavior of the orchestration's internal HTTP client is possible using [Azure Functions .NET dependency injection](../functions-dotnet-dependency-injection.md). This ability can be useful for making small behavioral changes. It can also be useful for unit testing the HTTP client by injecting mock objects.
482+
Customizing the behavior of the orchestration's internal HTTP client is possible using [Azure Functions .NET dependency injection](../functions-dotnet-dependency-injection.md) for the in-process worker. This ability can be useful for making small behavioral changes. It can also be useful for unit testing the HTTP client by injecting mock objects.
425483

426484
The following example demonstrates using dependency injection to disable TLS/SSL certificate validation for orchestrator functions that call external HTTP endpoints.
427485

0 commit comments

Comments
 (0)