Skip to content

Commit 195ee1c

Browse files
Merge pull request #268044 from mattchenderson/httpattrib
adding HTTP output binding attribute for ASP.NET Core integration
2 parents a61ad13 + 3323f4a commit 195ee1c

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

articles/azure-functions/dotnet-isolated-process-guide.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,42 @@ To write to an output binding, you must apply an output binding attribute to the
311311

312312
### Multiple output bindings
313313

314-
The data written to an output binding is always the return value of the function. If you need to write to more than one output binding, you must create a custom return type. This return type must have the output binding attribute applied to one or more properties of the class. The following example from an HTTP trigger writes to both the HTTP response and a queue output binding:
314+
The data written to an output binding is always the return value of the function. If you need to write to more than one output binding, you must create a custom return type. This return type must have the output binding attribute applied to one or more properties of the class. The following example is an HTTP-triggered function using [ASP.NET Core integration](#aspnet-core-integration) which writes to both the HTTP response and a queue output binding:
315315

316-
:::code language="csharp" source="~/azure-functions-dotnet-worker/samples/Extensions/MultiOutput/MultiOutput.cs" id="docsnippet_multiple_outputs":::
316+
```csharp
317+
public class MultipleOutputBindings
318+
{
319+
private readonly ILogger<MultipleOutputBindings> _logger;
320+
321+
public MultipleOutputBindings(ILogger<MultipleOutputBindings> logger)
322+
{
323+
_logger = logger;
324+
}
325+
326+
[Function("MultipleOutputBindings")]
327+
public MyOutputType Run([HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequest req)
328+
{
329+
_logger.LogInformation("C# HTTP trigger function processed a request.");
330+
var myObject = new MyOutputType
331+
{
332+
Result = new OkObjectResult("C# HTTP trigger function processed a request."),
333+
MessageText = "some output"
334+
};
335+
return myObject;
336+
}
337+
338+
public class MyOutputType
339+
{
340+
[HttpResult]
341+
public IActionResult Result { get; set; }
342+
343+
[QueueOutput("myQueue")]
344+
public string MessageText { get; set; }
345+
}
346+
}
347+
```
317348

318-
The response from an HTTP trigger is always considered an output, so a return value attribute isn't required.
349+
When using custom return types for multiple output bindings with ASP.NET Core integration, you must add the `[HttpResult]` attribute to the property that provides the result.
319350

320351
### SDK types
321352

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ The default return value for an HTTP-triggered function is:
1919
::: zone pivot="programming-language-csharp"
2020
## Attribute
2121

22-
Both [in-process](functions-dotnet-class-library.md) and [isolated worker process](dotnet-isolated-process-guide.md) C# libraries don't require an attribute. C# script instead uses a function.json configuration file as described in the [C# scripting guide](./functions-reference-csharp.md#http-output).
23-
2422
# [Isolated worker model](#tab/isolated-process)
2523

26-
A return value attribute isn't required. To learn more, see [Usage](#usage).
24+
A return value attribute isn't required when using [HttpResponseData]. However, when using a [ASP.NET Core integration](./dotnet-isolated-process-guide.md#aspnet-core-integration) and [multi-binding output objects](./dotnet-isolated-process-guide.md#multiple-output-bindings), the `[HttpResultAttribute]` attribute should be applied to the object property. The attribute takes no parameters. To learn more, see [Usage](#usage).
2725

2826
# [In-process model](#tab/in-process)
2927

3028
[!INCLUDE [functions-in-process-model-retirement-note](../../includes/functions-in-process-model-retirement-note.md)]
3129

32-
A return value attribute isn't required. To learn more, see [Usage](#usage).
30+
A return value attribute isn't required for a [class library](functions-dotnet-class-library.md). C# script instead uses a function.json configuration file as described in the [C# scripting guide](./functions-reference-csharp.md#http-output). To learn more, see [Usage](#usage).
3331

3432
---
3533

@@ -83,11 +81,21 @@ The following table explains the binding configuration properties that you set i
8381
To send an HTTP response, use the language-standard response patterns.
8482

8583
::: zone pivot="programming-language-csharp"
86-
The response type depends on the C# mode:
84+
85+
In .NET, the response type depends on the C# mode:
8786

8887
# [Isolated worker model](#tab/isolated-process)
8988

90-
The HTTP triggered function returns an [HttpResponseData](/dotnet/api/microsoft.azure.functions.worker.http.httpresponsedata) object or a `Task<HttpResponseData>`. If the app uses [ASP.NET Core integration in .NET Isolated](./dotnet-isolated-process-guide.md#aspnet-core-integration), it could also use [IActionResult], `Task<IActionResult>`, [HttpResponse], or `Task<HttpResponse>`.
89+
The HTTP triggered function returns an object of one of the following types:
90+
91+
- [IActionResult]<sup>1</sup> (or `Task<IActionResult>`)
92+
- [HttpResponse]<sup>1</sup> (or `Task<HttpResponse>`)
93+
- [HttpResponseData] (or `Task<HttpResponseData>`)
94+
- JSON serializable types representing the response body for a `200 OK` response.
95+
96+
<sup>1</sup> This type is only available when using [ASP.NET Core integration](./dotnet-isolated-process-guide.md#aspnet-core-integration).
97+
98+
When one of these types is used as part of [multi-binding output objects](./dotnet-isolated-process-guide.md#multiple-output-bindings), the `[HttpResult]` attribute should be applied to the object property. The attribute takes no parameters.
9199

92100
[IActionResult]: /dotnet/api/microsoft.aspnetcore.mvc.iactionresult
93101
[HttpResponse]: /dotnet/api/microsoft.aspnetcore.http.httpresponse
@@ -110,3 +118,5 @@ For example responses, see the [trigger examples](./functions-bindings-http-webh
110118
## Next steps
111119

112120
- [Run a function from an HTTP request](./functions-bindings-http-webhook-trigger.md)
121+
122+
[HttpResponseData]: /dotnet/api/microsoft.azure.functions.worker.http.httpresponsedata

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,11 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
510510
::: zone pivot="programming-language-csharp"
511511
## Attributes
512512

513-
Both [in-process](functions-dotnet-class-library.md) and [isolated worker process](dotnet-isolated-process-guide.md) C# libraries use the `HttpTriggerAttribute` to define the trigger binding. C# script instead uses a function.json configuration file as described in the [C# scripting guide](./functions-reference-csharp.md#http-trigger).
513+
Both the [isolated worker model](dotnet-isolated-process-guide.md) and the [in-process model](functions-dotnet-class-library.md) use the `HttpTriggerAttribute` to define the trigger binding. C# script instead uses a function.json configuration file as described in the [C# scripting guide](./functions-reference-csharp.md#http-trigger).
514514

515515
# [Isolated worker model](#tab/isolated-process)
516516

517-
In [isolated worker process](dotnet-isolated-process-guide.md) function apps, the `HttpTriggerAttribute` supports the following parameters:
517+
In [isolated worker model](dotnet-isolated-process-guide.md) function apps, the `HttpTriggerAttribute` supports the following parameters:
518518

519519
| Parameters | Description|
520520
|---------|----------------------|

0 commit comments

Comments
 (0)