Skip to content

Commit 6cf8243

Browse files
authored
Merge pull request #53052 from JeffKoMS/se-bugfix-157587
SE Bugfix 157587: updated unit 3 and knowledge check
2 parents 48fdefb + a115f8d commit 6cf8243

4 files changed

Lines changed: 108 additions & 44 deletions

File tree

learn-pr/wwl-azure/develop-azure-functions/3-create-triggers-bindings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
prefetch-feature-rollout: true
77
title: Create triggers and bindings
88
description: "Create triggers and bindings"
9-
ms.date: 05/27/2025
9+
ms.date: 01/05/2026
1010
author: wwlpublish
1111
ms.author: jeffko
1212
ms.topic: unit

learn-pr/wwl-azure/develop-azure-functions/6-knowledge-check.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
prefetch-feature-rollout: true
77
title: Module assessment
88
description: "Knowledge check"
9-
ms.date: 05/27/2025
9+
ms.date: 01/05/2026
1010
author: wwlpublish
1111
ms.author: jeffko
1212
ms.topic: unit
@@ -38,4 +38,15 @@ quiz:
3838
explanation: "Incorrect. Triggers only support the `in` direction."
3939
- content: "Connection value"
4040
isCorrect: false
41-
explanation: "Incorrect. A connection value is used to connect your function to other Azure services."
41+
explanation: "Incorrect. A connection value is used to connect your function to other Azure services."
42+
- content: "In the Node.js v4 programming model, how are triggers and bindings configured?"
43+
choices:
44+
- content: "In code using the `@azure/functions` package"
45+
isCorrect: true
46+
explanation: "Correct. Node.js v4 is code-first; you declare inputs/outputs in code and the runtime generates function.json."
47+
- content: "By editing function.json directly in the Azure portal"
48+
isCorrect: false
49+
explanation: "Incorrect. Editing function.json is for older models like Node.js v3; v4 uses code-first configuration."
50+
- content: "By adding entries to host.json"
51+
isCorrect: false
52+
explanation: "Incorrect. host.json controls host-wide settings, not per-function bindings."

learn-pr/wwl-azure/develop-azure-functions/includes/3-create-triggers-bindings.md

Lines changed: 93 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,24 @@ When you develop your functions locally, you need to take trigger and binding be
1414

1515
## Trigger and binding definitions
1616

17-
Triggers and bindings are defined differently depending on the development language.
17+
Triggers and bindings are defined differently depending on the development language and runtime model.
1818

1919
| Language | Configure triggers and bindings by... |
2020
|--|--|
21-
| C# class library | decorating methods and parameters with C# attributes |
21+
| C# class library | decorating methods and parameters with C# attributes (in-process or isolated worker) |
2222
| Java | decorating methods and parameters with Java annotations |
23-
| JavaScript/PowerShell/Python/TypeScript | updating *function.json* schema |
23+
| JavaScript/TypeScript | v4 programming model: define inputs/outputs in code using `@azure/functions`; v3: configure in a per-function *function.json* |
24+
| Python | v2 programming model: define inputs/outputs with decorators; v1: configure in *function.json* |
25+
| PowerShell | configure in *function.json* |
2426

25-
For languages that rely on *function.json*, the portal provides a UI for adding bindings in the **Integration** tab. You can also edit the file directly in the portal in the **Code + test** tab of your function.
27+
> [!NOTE]
28+
> In modern models (Node.js v4 and Python v2), you author trigger and binding configuration in code and the runtime generates the corresponding *function.json*. Older models (Node.js v3, Python v1, PowerShell) use *function.json* directly. You can't mix programming models within the same function app.
29+
30+
For languages that rely on *function.json* (for example, Node.js v3, Python v1, and PowerShell), the portal provides a UI for adding bindings in the **Integration** tab. You can also edit the file directly in the portal in the **Code + test** tab of your function. For code-first models like Node.js v4 and Python v2, configure bindings in code in your local project; the portal reflects configuration but might not support direct edits.
2631

2732
In .NET and Java, the parameter type defines the data type for input data. For instance, use `string` to bind to the text of a queue trigger, a byte array to read as binary, and a custom type to deserialize to an object. Since .NET class library functions and Java functions don't rely on *function.json* for binding definitions, they can't be created and edited in the portal. C# portal editing is based on C# script, which uses *function.json* instead of attributes.
2833

29-
For languages that are dynamically typed such as JavaScript, use the `dataType` property in the *function.json* file. For example, to read the content of an HTTP request in binary format, set `dataType` to `binary`:
34+
For languages that are dynamically typed such as JavaScript (using the v3 model) or PowerShell, use the `dataType` property in the *function.json* file. For example, to read the content of an HTTP request in binary format, set `dataType` to `binary`:
3035

3136
```json
3237
{
@@ -49,64 +54,112 @@ All triggers and bindings have a direction property in the *function.json* file:
4954

5055
When you use attributes in a class library to configure triggers and bindings, the direction is provided in an attribute constructor or inferred from the parameter type.
5156

52-
## Azure Functions trigger and binding example
57+
## Azure Functions trigger and binding examples
5358

54-
Suppose you want to write a new row to Azure Table storage whenever a new message appears in Azure Queue storage. This scenario can be implemented using an Azure Queue storage trigger and an Azure Table storage output binding.
59+
Suppose you want to write a message to Azure Queue storage whenever an HTTP request is received. You can implement this with an HTTP trigger and a Storage Queue output binding. The configuration approach depends on your language and programming model.
5560

56-
Here's a *function.json* file for this scenario.
61+
Here's a legacy *function.json* file for this scenario (applicable to Node.js v3, Python v1, or PowerShell).
5762

5863
```json
5964
{
60-
"disabled": false,
65+
"disabled": false,
6166
"bindings": [
6267
{
63-
"type": "queueTrigger",
68+
"type": "httpTrigger",
6469
"direction": "in",
65-
"name": "myQueueItem",
66-
"queueName": "myqueue-items",
67-
"connection":"MyStorageConnectionAppSetting"
70+
"name": "req",
71+
"authLevel": "function",
72+
"methods": ["get","post"]
6873
},
69-
{
70-
"tableName": "Person",
71-
"connection": "MyStorageConnectionAppSetting",
72-
"name": "tableBinding",
73-
"type": "table",
74-
"direction": "out"
75-
}
74+
{
75+
"type": "queue",
76+
"direction": "out",
77+
"name": "outqueue",
78+
"queueName": "outqueue",
79+
"connection": "AzureWebJobsStorage"
80+
}
7681
]
7782
}
7883
```
7984

80-
The first element in the `bindings` array is the Queue storage trigger. The `type` and `direction` properties identify the trigger. The `name` property identifies the function parameter that receives the queue message content. The name of the queue to monitor is in `queueName`, and the connection string is in the app setting identified by `connection`.
85+
The first element in the `bindings` array is the HTTP trigger. The `type` and `direction` properties identify the trigger. The `name` property identifies the function parameter that receives the HTTP request, and `methods` lists the supported HTTP verbs.
86+
87+
The second element in the `bindings` array is the Storage Queue output binding. The `type` and `direction` properties identify the binding. The `name` property specifies how the function provides the new queue message, the `queueName` identifies the queue, and `connection` refers to the app setting that holds the storage connection string.
8188

82-
The second element in the `bindings` array is the Azure Table Storage output binding. The `type` and `direction` properties identify the binding. The `name` property specifies how the function provides the new table row, in this case by using the function return value. The name of the table is in `tableName`, and the connection string is in the app setting identified by `connection`.
89+
> [!NOTE]
90+
> Disabling a function via the `disabled` property in *function.json* is legacy behavior. Prefer using the app setting `AzureWebJobs.<FunctionName>.Disabled=true`.
8391
84-
### C# function example
92+
### C# (isolated worker) example
8593

86-
Following is the same example represented in a C# function. The same trigger and binding information, queue and table names, storage accounts, and function parameters for input and output are provided by attributes instead of a *function.json* file.
94+
This example shows an HTTP-triggered function that writes a message to a Storage Queue using an output binding defined by attributes. For more information, see [C# isolated worker guide](/azure/azure-functions/dotnet-isolated-process-guide).
8795

8896
```csharp
89-
public static class QueueTriggerTableOutput
97+
using Microsoft.Azure.Functions.Worker;
98+
using Microsoft.Azure.Functions.Worker.Http;
99+
100+
public static class HttpToQueue
90101
{
91-
[FunctionName("QueueTriggerTableOutput")]
92-
[return: Table("outTable", Connection = "MY_TABLE_STORAGE_ACCT_APP_SETTING")]
93-
public static Person Run(
94-
[QueueTrigger("myqueue-items", Connection = "MY_STORAGE_ACCT_APP_SETTING")]JObject order,
95-
ILogger log)
102+
[Function("HttpToQueue")]
103+
public static MultiResponse Run(
104+
[HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req)
96105
{
97-
return new Person() {
98-
PartitionKey = "Orders",
99-
RowKey = Guid.NewGuid().ToString(),
100-
Name = order["Name"].ToString(),
101-
MobileNumber = order["MobileNumber"].ToString() };
106+
var message = "Processed request";
107+
return new MultiResponse
108+
{
109+
Messages = new[] { message },
110+
HttpResponse = req.CreateResponse(System.Net.HttpStatusCode.OK)
111+
};
102112
}
103113
}
104114

105-
public class Person
115+
public class MultiResponse
106116
{
107-
public string PartitionKey { get; set; }
108-
public string RowKey { get; set; }
109-
public string Name { get; set; }
110-
public string MobileNumber { get; set; }
117+
[QueueOutput("outqueue", Connection = "AzureWebJobsStorage")]
118+
public string[] Messages { get; set; }
119+
public HttpResponseData HttpResponse { get; set; }
111120
}
112121
```
122+
123+
### Node.js (v4 programming model) example
124+
125+
In the v4 Node.js programming model, you configure inputs and outputs in code using `@azure/functions`. For more information, see [Node.js developer guide (v4)](/azure/azure-functions/functions-reference-node?pivots=nodejs-model-v4#inputs-and-outputs).
126+
127+
```javascript
128+
import { app, output } from "@azure/functions";
129+
130+
const queueOutput = output.storageQueue({
131+
queueName: "outqueue",
132+
connection: "AzureWebJobsStorage"
133+
});
134+
135+
app.http("HttpToQueue", {
136+
methods: ["GET", "POST"],
137+
authLevel: "function",
138+
extraOutputs: [queueOutput],
139+
handler: async (request, context) => {
140+
const body = await request.text();
141+
context.extraOutputs.set(queueOutput, body || "Processed request");
142+
return { status: 200, body: "Queued" };
143+
}
144+
});
145+
```
146+
147+
### Python (v2 programming model) example
148+
149+
In the v2 Python programming model, you use decorators to define bindings. The runtime generates *function.json* for you. Visit the [Python developer guide](/azure/azure-functions/functions-reference-python) for more information.
150+
151+
```python
152+
import azure.functions as func
153+
154+
app = func.FunctionApp()
155+
156+
@app.route(route="HttpToQueue", auth_level=func.AuthLevel.FUNCTION)
157+
@app.queue_output(arg_name="msg", queue_name="outqueue", connection="AzureWebJobsStorage")
158+
def HttpToQueue(req: func.HttpRequest, msg: func.Out[str]) -> func.HttpResponse:
159+
body = req.get_body().decode("utf-8") if req.get_body() else "Processed request"
160+
msg.set(body)
161+
return func.HttpResponse("Queued", status_code=200)
162+
```
163+
164+
> [!NOTE]
165+
> In Node.js v4 and Python v2, the runtime generates *function.json* from your code. Avoid editing *function.json* directly in the portal for these models; make changes in code and republish.

learn-pr/wwl-azure/develop-azure-functions/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
prefetch-feature-rollout: true
66
title: Develop Azure Functions
77
description: "Learn how to create and deploy Azure Functions."
8-
ms.date: 05/27/2025
8+
ms.date: 01/05/2026
99
author: JeffKoMS
1010
ms.author: jeffko
1111
ms.topic: module

0 commit comments

Comments
 (0)