Skip to content

Commit a44c470

Browse files
committed
add nodejs v4 examples
Signed-off-by: Hannah Hunter <[email protected]>
1 parent 7137fc1 commit a44c470

9 files changed

+476
-8
lines changed

articles/azure-functions/functions-bindings-dapr-input-secret.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ public void run(
6868

6969
::: zone pivot="programming-language-javascript"
7070

71+
# [Node.js v4](#tab/v4)
72+
73+
In the following example, the Dapr secret input binding is paired with a Dapr invoke trigger, which is registered by the `app` object:
74+
75+
```javascript
76+
app.generic('RetrieveSecret', {
77+
trigger: trigger.generic({
78+
type: 'daprServiceInvocationTrigger',
79+
name: "payload"
80+
}),
81+
extraInputs: [daprSecretInput],
82+
handler: async (request, context) => {
83+
context.log("Node function processed a RetrieveSecret request from the Dapr Runtime.");
84+
const daprSecretInputValue = context.extraInputs.get(daprSecretInput);
85+
86+
// print the fetched secret value
87+
for (var key in daprSecretInputValue) {
88+
context.log(`Stored secret: Key=${key}, Value=${daprSecretInputValue[key]}`);
89+
}
90+
}
91+
});
92+
```
93+
94+
# [Node.js v3](#tab/v3)
95+
7196
The following examples show Dapr triggers in a _function.json_ file and JavaScript code that uses those bindings.
7297

7398
Here's the _function.json_ file for `daprServiceInvocationTrigger`:
@@ -102,6 +127,8 @@ module.exports = async function (context) {
102127
};
103128
```
104129

130+
---
131+
105132
::: zone-end
106133

107134
::: zone pivot="programming-language-powershell"
@@ -266,7 +293,33 @@ The `DaprSecretInput` annotation allows you to have your function access a secre
266293

267294
::: zone-end
268295

269-
::: zone pivot="programming-language-javascript, programming-language-powershell"
296+
::: zone pivot="programming-language-javascript"
297+
298+
# [Node.js v4](#tab/v4)
299+
300+
The following table explains the binding configuration properties that you set in the code.
301+
302+
|Property | Description |
303+
|-----------------------|-------------|
304+
|**key** | The secret key value. |
305+
|**secretStoreName** | Name of the secret store as defined in the _local-secret-store.yaml_ component file. |
306+
|**metadata** | The metadata namespace. |
307+
308+
# [Node.js v3](#tab/v3)
309+
310+
The following table explains the binding configuration properties that you set in the function.json file.
311+
312+
|function.json property | Description |
313+
|-----------------------|-------------|
314+
|**key** | The secret key value. |
315+
|**secretStoreName** | Name of the secret store as defined in the _local-secret-store.yaml_ component file. |
316+
|**metadata** | The metadata namespace. |
317+
318+
---
319+
320+
::: zone-end
321+
322+
::: zone pivot="programming-language-powershell"
270323

271324
The following table explains the binding configuration properties that you set in the function.json file.
272325

articles/azure-functions/functions-bindings-dapr-input-state.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ public String run(
7070

7171
::: zone pivot="programming-language-javascript"
7272

73+
# [Node.js v4](#tab/v4)
74+
75+
In the following example, the Dapr invoke input binding is added as an `extraInput` and paired with an HTTP trigger, which is registered by the `app` object:
76+
77+
```javascript
78+
app.generic('StateInputBinding', {
79+
trigger: trigger.generic({
80+
type: 'httpTrigger',
81+
authLevel: 'anonymous',
82+
methods: ['GET'],
83+
route: "state/{key}",
84+
name: "req"
85+
}),
86+
extraInputs: [daprStateInput],
87+
handler: async (request, context) => {
88+
context.log("Node HTTP trigger function processed a request.");
89+
90+
const daprStateInputValue = context.extraInputs.get(daprStateInput);
91+
// print the fetched state value
92+
context.log(daprStateInputValue);
93+
94+
return daprStateInputValue;
95+
}
96+
});
97+
```
98+
99+
# [Node.js v3](#tab/v3)
100+
73101
The following examples show Dapr triggers in a _function.json_ file and JavaScript code that uses those bindings.
74102

75103
Here's the _function.json_ file for `daprState`:
@@ -98,6 +126,8 @@ module.exports = async function (context, req) {
98126
};
99127
```
100128

129+
---
130+
101131
::: zone-end
102132

103133
::: zone pivot="programming-language-powershell"
@@ -251,13 +281,26 @@ The `DaprStateInput` annotation allows you to read Dapr state into your function
251281

252282
::: zone pivot="programming-language-javascript"
253283

284+
# [Node.js v4](#tab/v4)
285+
286+
The following table explains the binding configuration properties that you set in the code.
287+
288+
|Property | Description |
289+
|-----------------------|-------------|
290+
|**stateStore** | The name of the state store. |
291+
|**key** | The name of the key to retrieve from the specified state store. |
292+
293+
# [Node.js v3](#tab/v3)
294+
254295
The following table explains the binding configuration properties that you set in the function.json file.
255296

256297
|function.json property | Description |
257298
|-----------------------|-------------|
258299
|**stateStore** | The name of the state store. |
259300
|**key** | The name of the key to retrieve from the specified state store. |
260301

302+
---
303+
261304
::: zone-end
262305

263306
::: zone pivot="programming-language-powershell"

articles/azure-functions/functions-bindings-dapr-output-invoke.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,33 @@ public String run(
8585

8686
::: zone pivot="programming-language-javascript"
8787

88+
# [Node.js v4](#tab/v4)
89+
90+
In the following example, the Dapr invoke output binding is paired with an HTTP trigger, which is registered by the `app` object:
91+
92+
```javascript
93+
app.generic('InvokeOutputBinding', {
94+
trigger: trigger.generic({
95+
type: 'httpTrigger',
96+
authLevel: 'anonymous',
97+
methods: ['POST'],
98+
route: "invoke/{appId}/{methodName}",
99+
name: "req"
100+
}),
101+
return: daprInvokeOutput,
102+
handler: async (request, context) => {
103+
context.log("Node HTTP trigger function processed a request.");
104+
105+
const payload = await request.text();
106+
context.log(JSON.stringify(payload));
107+
108+
return { body: payload };
109+
}
110+
});
111+
```
112+
113+
# [Node.js v3](#tab/v3)
114+
88115
The following examples show Dapr triggers in a _function.json_ file and JavaScript code that uses those bindings.
89116

90117
Here's the _function.json_ file for `daprInvoke`:
@@ -115,6 +142,8 @@ module.exports = async function (context, req) {
115142
};
116143
```
117144

145+
---
146+
118147
::: zone-end
119148

120149
::: zone pivot="programming-language-powershell"
@@ -285,7 +314,35 @@ The `DaprInvokeOutput` annotation allows you to have your function invoke and li
285314

286315
::: zone-end
287316

288-
::: zone pivot="programming-language-javascript, programming-language-powershell"
317+
::: zone pivot="programming-language-javascript"
318+
319+
# [Node.js v4](#tab/v4)
320+
321+
The following table explains the binding configuration properties that you set in the code.
322+
323+
|Property | Description| Can be sent via Attribute | Can be sent via RequestBody |
324+
|-----------------------|------------| :---------------------: | :-----------------------: |
325+
|**appId** | The app ID of the application involved in the invoke binding. | :heavy_check_mark: | :heavy_check_mark: |
326+
|**methods** | Post or get. | :heavy_check_mark: | :heavy_check_mark: |
327+
| **body** | _Required._ The body of the request. | :x: | :heavy_check_mark: |
328+
329+
# [Node.js v3](#tab/v3)
330+
331+
The following table explains the binding configuration properties that you set in the function.json file.
332+
333+
|function.json property | Description| Can be sent via Attribute | Can be sent via RequestBody |
334+
|-----------------------|------------| :---------------------: | :-----------------------: |
335+
|**appId** | The app ID of the application involved in the invoke binding. | :heavy_check_mark: | :heavy_check_mark: |
336+
|**methodName** | The name of the method variable. | :heavy_check_mark: | :heavy_check_mark: |
337+
|**httpVerb** | Post or get. | :heavy_check_mark: | :heavy_check_mark: |
338+
| **body** | _Required._ The body of the request. | :x: | :heavy_check_mark: |
339+
340+
---
341+
342+
::: zone-end
343+
344+
::: zone pivot="programming-language-powershell"
345+
289346
The following table explains the binding configuration properties that you set in the function.json file.
290347

291348
|function.json property | Description| Can be sent via Attribute | Can be sent via RequestBody |

articles/azure-functions/functions-bindings-dapr-output-publish.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,32 @@ public String run(
7474

7575
::: zone pivot="programming-language-javascript"
7676

77+
# [Node.js v4](#tab/v4)
78+
79+
In the following example, the Dapr publish output binding is paired with an HTTP trigger, which is registered by the `app` object:
80+
81+
```javascript
82+
app.generic('PublishOutputBinding', {
83+
trigger: trigger.generic({
84+
type: 'httpTrigger',
85+
authLevel: 'anonymous',
86+
methods: ['POST'],
87+
route: "topic/{topicName}",
88+
name: "req"
89+
}),
90+
return: daprPublishOutput,
91+
handler: async (request, context) => {
92+
context.log("Node HTTP trigger function processed a request.");
93+
const payload = await request.text();
94+
context.log(JSON.stringify(payload));
95+
96+
return { payload: payload };
97+
}
98+
});
99+
```
100+
101+
# [Node.js v3](#tab/v3)
102+
77103
The following examples show Dapr triggers in a _function.json_ file and JavaScript code that uses those bindings.
78104

79105
Here's the _function.json_ file for `daprPublish`:
@@ -103,6 +129,8 @@ module.exports = async function (context, req) {
103129
};
104130
```
105131

132+
---
133+
106134
::: zone-end
107135

108136
::: zone pivot="programming-language-powershell"
@@ -267,7 +295,33 @@ The `DaprPublishOutput` annotation allows you to have a function access a publis
267295

268296
::: zone-end
269297

270-
::: zone pivot="programming-language-javascript, programming-language-powershell"
298+
::: zone pivot="programming-language-javascript"
299+
300+
# [Node.js v4](#tab/v4)
301+
302+
The following table explains the binding configuration properties that you set in the code.
303+
304+
|Property | Description| Can be sent via Attribute | Can be sent via RequestBody |
305+
|-----------------------|------------| :---------------------: | :-----------------------: |
306+
|**pubsubname** | The name of the publisher component service. | :heavy_check_mark: | :heavy_check_mark: |
307+
|**topic** | The name/identifier of the publisher topic. | :heavy_check_mark: | :heavy_check_mark: |
308+
| **payload** | _Required._ The message being published. | :x: | :heavy_check_mark: |
309+
310+
# [Node.js v3](#tab/v3)
311+
312+
The following table explains the binding configuration properties that you set in the function.json file.
313+
314+
|function.json property | Description| Can be sent via Attribute | Can be sent via RequestBody |
315+
|-----------------------|------------| :---------------------: | :-----------------------: |
316+
|**pubsubname** | The name of the publisher component service. | :heavy_check_mark: | :heavy_check_mark: |
317+
|**topic** | The name/identifier of the publisher topic. | :heavy_check_mark: | :heavy_check_mark: |
318+
| **payload** | _Required._ The message being published. | :x: | :heavy_check_mark: |
319+
320+
---
321+
322+
::: zone-end
323+
324+
::: zone pivot="programming-language-powershell"
271325

272326
The following table explains the binding configuration properties that you set in the _function.json_ file.
273327

articles/azure-functions/functions-bindings-dapr-output-state.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ public String run(
8080

8181
::: zone pivot="programming-language-javascript"
8282

83+
# [Node.js v4](#tab/v4)
84+
85+
In the following example, the Dapr state output binding is paired with an HTTP trigger, which is registered by the `app` object:
86+
87+
```javascript
88+
app.generic('StateOutputBinding', {
89+
trigger: trigger.generic({
90+
type: 'httpTrigger',
91+
authLevel: 'anonymous',
92+
methods: ['POST'],
93+
route: "state/{key}",
94+
name: "req"
95+
}),
96+
return: daprStateOutput,
97+
handler: async (request, context) => {
98+
context.log("Node HTTP trigger function processed a request.");
99+
100+
const payload = await request.text();
101+
context.log(JSON.stringify(payload));
102+
103+
return { value : payload };
104+
}
105+
});
106+
```
107+
108+
# [Node.js v3](#tab/v3)
109+
83110
The following examples show Dapr triggers in a _function.json_ file and JavaScript code that uses those bindings.
84111

85112
Here's the _function.json_ file for `daprState` output:
@@ -114,6 +141,8 @@ module.exports = async function (context, req) {
114141
};
115142
```
116143

144+
---
145+
117146
::: zone-end
118147

119148
::: zone pivot="programming-language-powershell"
@@ -277,7 +306,34 @@ The `DaprStateOutput` annotation allows you to function access a state store.
277306

278307
::: zone-end
279308

280-
::: zone pivot="programming-language-javascript, programming-language-powershell"
309+
::: zone pivot="programming-language-javascript"
310+
311+
# [Node.js v4](#tab/v4)
312+
313+
The following table explains the binding configuration properties that you set in the code.
314+
315+
|Property | Description| Can be sent via Attribute | Can be sent via RequestBody |
316+
|-----------------------|------------| :---------------------: | :-----------------------: |
317+
| **stateStore** | The name of the state store to save state. | :heavy_check_mark: | :x: |
318+
| **key** | The name of the key to save state within the state store. | :heavy_check_mark: | :heavy_check_mark: |
319+
| **value** | _Required._ The value being stored. | :x: | :heavy_check_mark: |
320+
321+
322+
# [Node.js v3](#tab/v3)
323+
324+
The following table explains the binding configuration properties that you set in the function.json file.
325+
326+
|function.json property | Description| Can be sent via Attribute | Can be sent via RequestBody |
327+
|-----------------------|------------| :---------------------: | :-----------------------: |
328+
| **stateStore** | The name of the state store to save state. | :heavy_check_mark: | :x: |
329+
| **key** | The name of the key to save state within the state store. | :heavy_check_mark: | :heavy_check_mark: |
330+
| **value** | _Required._ The value being stored. | :x: | :heavy_check_mark: |
331+
332+
---
333+
334+
::: zone-end
335+
336+
::: zone pivot="programming-language-powershell"
281337

282338
The following table explains the binding configuration properties that you set in the _function.json_ file.
283339

0 commit comments

Comments
 (0)