Skip to content

Commit c190f9a

Browse files
Merge pull request #258720 from mattchenderson/aspnetcore-default
updating quickstart to use ASP.NET Core integration
2 parents 3c39452 + 0b50b4c commit c190f9a

5 files changed

+59
-13
lines changed

articles/azure-functions/create-first-function-cli-csharp.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,39 @@ In Azure Functions, a function project is a container for one or more individual
6767
If desired, you can skip to [Run the function locally](#run-the-function-locally) and examine the file contents later.
6868

6969
#### HttpExample.cs
70-
71-
The function code generated from the template depends on the type of compiled C# project.
72-
73-
*HttpExample.cs* contains a `Run` method that receives request data in the `req` variable is an [HttpRequestData](/dotnet/api/microsoft.azure.functions.worker.http.httprequestdata) object that's decorated with the **HttpTriggerAttribute**, which defines the trigger behavior. Because of the isolated worker process model, `HttpRequestData` is a representation of the actual `HttpRequest`, and not the request object itself.
74-
75-
:::code language="csharp" source="~/functions-docs-csharp/http-trigger-isolated/HttpExample.cs":::
76-
77-
The return object is an [HttpResponseData](/dotnet/api/microsoft.azure.functions.worker.http.httpresponsedata) object that contains the data that's handed back to the HTTP response.
70+
71+
*HttpExample.cs* contains a `Run` method that receives request data in the `req` variable as an [HttpRequest](/dotnet/api/microsoft.aspnetcore.http.httprequest) object. That parameter is decorated with the **HttpTriggerAttribute**, to define the trigger behavior.
72+
73+
```csharp
74+
using System.Net;
75+
using Microsoft.Azure.Functions.Worker;
76+
using Microsoft.Extensions.Logging;
77+
using Microsoft.AspNetCore.Http;
78+
using Microsoft.AspNetCore.Mvc;
79+
80+
namespace Company.Function
81+
{
82+
public class HttpExample
83+
{
84+
private readonly ILogger<HttpExample> _logger;
85+
86+
public HttpExample(ILogger<HttpExample> logger)
87+
{
88+
_logger = logger;
89+
}
90+
91+
[Function("HttpExample")]
92+
public IActionResult Run([HttpTrigger(AuthorizationLevel.AuthLevelValue, "get", "post")] HttpRequest req)
93+
{
94+
_logger.LogInformation("C# HTTP trigger function processed a request.");
95+
96+
return new OkObjectResult("Welcome to Azure Functions!");
97+
}
98+
}
99+
}
100+
```
101+
102+
The return object is an [IActionResult](/dotnet/api/microsoft.aspnetcore.mvc.iactionresult) object that contains the data that's handed back to the HTTP response.
78103

79104
To learn more, see [Azure Functions HTTP triggers and bindings](./functions-bindings-http-webhook.md?tabs=csharp).
80105

articles/azure-functions/create-first-function-vs-code-csharp.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ In this section, you use Visual Studio Code to create a local Azure Functions pr
4545
|--|--|
4646
|**Select a language for your function project**|Choose `C#`.|
4747
| **Select a .NET runtime** | Choose `.NET 8.0 Isolated (LTS)`.|
48-
|**Select a template for your project's first function**|Choose `HTTP trigger`.|
48+
|**Select a template for your project's first function**|Choose `HTTP trigger`.<sup>1</sup>|
4949
|**Provide a function name**|Type `HttpExample`.|
5050
|**Provide a namespace** | Type `My.Functions`. |
5151
|**Authorization level**|Choose `Anonymous`, which enables anyone to call your function endpoint. To learn about authorization level, see [Authorization keys](functions-bindings-http-webhook-trigger.md#authorization-keys).|
5252
|**Select how you would like to open your project**|Select `Open in current window`.|
5353

54+
<sup>1</sup> Depending on your VS Code settings, you may need to use the `Change template filter` option to see the full list of templates.
55+
5456
1. Visual Studio Code uses the provided information and generates an Azure Functions project with an HTTP trigger. You can view the local project files in the Explorer. For more information about the files that are created, see [Generated project files](functions-develop-vs-code.md?tabs=csharp#generated-project-files).
5557

5658
[!INCLUDE [functions-run-function-test-local-vs-code-csharp](../../includes/functions-run-function-test-local-vs-code-csharp.md)]

articles/azure-functions/functions-create-your-first-function-visual-studio.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ Your function definition should now look like the following code:
7777

7878
```csharp
7979
[Function("HttpExample")]
80-
public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
81-
FunctionContext executionContext)
80+
public IActionResult Run([HttpTrigger(AuthorizationLevel.AuthLevelValue, "get", "post")] HttpRequest req)
81+
{
82+
return new OkObjectResult("Welcome to Azure Functions!");
83+
}
8284
```
8385

8486
Now that you've renamed the function, you can test it on your local computer.

articles/azure-functions/functions-develop-vs-code.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ The Functions extension lets you create a function app project, along with your
118118

119119
:::image type="content" source="./media/functions-develop-vs-code/select-http-trigger.png" alt-text="Screenshot for selecting H T T P trigger.":::
120120

121+
> [!TIP]
122+
> You can view additional templates by selecting the `Change template filter` option and setting it to "Core" or "All".
123+
121124
1. Type **HttpExample** for the function name and select Enter, and then select **Function** authorization. This authorization level requires you to provide a [function key](functions-bindings-http-webhook-trigger.md#authorization-keys) when you call the function endpoint.
122125

123126
:::image type="content" source="./media/functions-develop-vs-code/create-function-auth.png" alt-text="Screenshot for creating function authorization.":::

includes/functions-add-output-binding-example-all-languages.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ The following example shows the function definition after adding a [Queue Storag
1111
### [Isolated process](#tab/isolated-process)
1212
Because an HTTP triggered function also returns an HTTP response, the function returns a `MultiResponse` object, which represents both the HTTP and queue output.
1313

14-
:::code language="csharp" source="~/functions-docs-csharp/functions-add-output-binding-storage-queue-isolated/HttpExample.cs" range="11-14":::
14+
```csharp
15+
[Function("HttpExample")]
16+
public static MultiResponse Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
17+
FunctionContext executionContext)
18+
{
19+
```
1520

1621
This example is the definition of the `MultiResponse` object that includes the output binding:
1722

18-
:::code language="csharp" source="~/functions-docs-csharp/functions-add-output-binding-storage-queue-isolated/HttpExample.cs" range="33-38" highlight="3":::
23+
```csharp
24+
public class MultiResponse
25+
{
26+
[QueueOutput("outqueue",Connection = "AzureWebJobsStorage")]
27+
public string[] Messages { get; set; }
28+
public IActionResult HttpResponse { get; set; }
29+
}
30+
```
31+
32+
When applying that example to your own project, you might need to change `HttpRequest` to `HttpRequestData` and `IActionResult` to `HttpResponseData`, depending on if you are using [ASP.NET Core integration](../articles/azure-functions/dotnet-isolated-process-guide.md#aspnet-core-integration) or not.
1933

2034
### [In-process](#tab/in-process)
2135
:::code language="csharp" source="~/functions-docs-csharp/functions-add-output-binding-storage-queue-cli/HttpExample.cs" range="14-18" highlight="4":::

0 commit comments

Comments
 (0)