You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This article explains how return values work inside a function.
13
+
This article explains how return values work inside a function. In languages that have a return value, you can bind a function [output binding](./functions-triggers-bindings.md#binding-direction) to the return value.
13
14
14
-
In languages that have a return value, you can bind a function [output binding](./functions-triggers-bindings.md#binding-direction) to the return value:
15
+
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
15
16
16
-
* In a C# class library, apply the output binding attribute to the method return value.
17
-
* In Java, apply the output binding annotation to the function method.
18
-
* In other languages, set the `name` property in *function.json* to `$return`.
17
+
Set the `name` property in *function.json* to `$return`. If there are multiple output bindings, use the return value for only one of them.
19
18
20
-
If there are multiple output bindings, use the return value for only one of them.
19
+
::: zone-end
21
20
22
-
In C# and C# script, alternative ways to send data to an output binding are `out` parameters and [collector objects](functions-reference-csharp.md#writing-multiple-output-values).
21
+
::: zone pivot="programming-language-csharp"
23
22
24
-
# [C#](#tab/csharp)
23
+
How return values are used depends on the C# mode you're using in your function app:
24
+
25
+
# [In-process](#tab/in-process)
26
+
27
+
28
+
In a C# class library, apply the output binding attribute to the method return value. In C# and C# script, alternative ways to send data to an output binding are `out` parameters and [collector objects](functions-reference-csharp.md#writing-multiple-output-values).
25
29
26
30
Here's C# code that uses the return value for an output binding, followed by an async example:
27
31
@@ -47,62 +51,15 @@ public static Task<string> Run([QueueTrigger("inputqueue")]WorkItem input, ILogg
47
51
}
48
52
```
49
53
50
-
# [C# Script](#tab/csharp-script)
51
-
52
-
Here's the output binding in the *function.json* file:
53
-
54
-
```json
55
-
{
56
-
"name": "$return",
57
-
"type": "blob",
58
-
"direction": "out",
59
-
"path": "output-container/{id}"
60
-
}
61
-
```
62
-
63
-
Here's the C# script code, followed by an async example:
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-csharp.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -217,7 +217,36 @@ The `#load` directive works only with *.csx* files, not with *.cs* files.
217
217
218
218
## Binding to method return value
219
219
220
-
You can use a method return value for an output binding, by using the name `$return` in *function.json*. For examples, see [Triggers and bindings](./functions-bindings-return-value.md).
220
+
You can use a method return value for an output binding, by using the name `$return` in *function.json*.
221
+
222
+
```json
223
+
{
224
+
"name": "$return",
225
+
"type": "blob",
226
+
"direction": "out",
227
+
"path": "output-container/{id}"
228
+
}
229
+
```
230
+
231
+
Here's the C# script code using the return value, followed by an async example:
Use the return value only if a successful function execution always results in a return value to pass to the output binding. Otherwise, use `ICollector` or `IAsyncCollector`, as shown in the following section.
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-fsharp.md
+31-11Lines changed: 31 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,14 +18,14 @@ F# for Azure Functions is a solution for easily running small pieces of code, or
18
18
19
19
This article assumes that you've already read the [Azure Functions developer reference](functions-reference.md).
20
20
21
-
## How .fsx works
21
+
## How an F# script works
22
22
An `.fsx` file is an F# script. It can be thought of as an F# project that's contained in a single file. The file contains both the code for your program (in this case, your Azure Function) and directives for managing dependencies.
23
23
24
24
When you use an `.fsx` for an Azure Function, commonly required assemblies are automatically included for you, allowing you to focus on the function rather than "boilerplate" code.
25
25
26
26
## Folder structure
27
27
28
-
The folder structure for an F# script project looks like the following:
28
+
The folder structure for an F# script project adheres to the following pattern:
29
29
30
30
```
31
31
FunctionsProject
@@ -44,7 +44,7 @@ FunctionsProject
44
44
45
45
There's a shared [host.json](functions-host-json.md) file that can be used to configure the function app. Each function has its own code file (.fsx) and binding configuration file (function.json).
46
46
47
-
The binding extensions required in [version 2.x and later versions](functions-versions.md) of the Functions runtime are defined in the `extensions.csproj` file, with the actual library files in the `bin` folder. When developing locally, you must [register binding extensions](./functions-bindings-register.md#extension-bundles). When developing functions in the Azure portal, this registration is done for you.
47
+
The binding extensions required in [version 2.x and later versions](functions-versions.md) of the Functions runtime are defined in the `extensions.csproj` file, with the actual library files in the `bin` folder. When you're developing locally, you must [register binding extensions](./functions-bindings-register.md#extension-bundles). When you're developing functions in the Azure portal, this registration is done for you.
48
48
49
49
## Binding to arguments
50
50
Each binding supports some set of arguments, as detailed in the [Azure Functions triggers and bindings developer reference](functions-triggers-bindings.md). For example, one of the argument bindings a blob trigger supports is a POCO, which can be expressed using an F# record. For example:
@@ -85,8 +85,28 @@ let Run(input: string, item: byref<Item>) =
85
85
item <- result
86
86
```
87
87
88
+
You can use a method return value for an output binding, by using the name `$return` in *function.json*:
89
+
90
+
```json
91
+
{
92
+
"name": "$return",
93
+
"type": "blob",
94
+
"direction": "out",
95
+
"path": "output-container/{id}"
96
+
}
97
+
```
98
+
99
+
Here's the F# code that uses the return value:
100
+
101
+
```fsharp
102
+
let Run(input: WorkItem, log: ILogger) =
103
+
let json = String.Format("{{ \"id\": \"{0}\" }}", input.Id)
To log output to your [streaming logs](../app-service/troubleshoot-diagnostic-logs.md) in F#, your function should take an argument of type [ILogger](/dotnet/api/microsoft.extensions.logging.ilogger). For consistency, we recommend this argument is named `log`. For example:
109
+
To log output to your [streaming logs](../app-service/troubleshoot-diagnostic-logs.md) in F#, your function should take an argument of type [`ILogger`](/dotnet/api/microsoft.extensions.logging.ilogger). For consistency, we recommend this argument is named `log`. For example:
90
110
91
111
```fsharp
92
112
let Run(blob: string, output: byref<string>, log: ILogger) =
@@ -167,7 +187,7 @@ The following assemblies are automatically added by the Azure Functions hosting
167
187
*`System.Web.Http`
168
188
*`System.Net.Http.Formatting`.
169
189
170
-
In addition, the following assemblies are special cased and may be referenced by simplename (e.g. `#r "AssemblyName"`):
190
+
In addition, the following assemblies are special cased and may be referenced by simple name (e.g. `#r "AssemblyName"`):
171
191
172
192
*`Newtonsoft.Json`
173
193
*`Microsoft.WindowsAzure.Storage`
@@ -178,7 +198,7 @@ In addition, the following assemblies are special cased and may be referenced by
178
198
If you need to reference a private assembly, you can upload the assembly file into a `bin` folder relative to your function and reference it by using the file name (e.g. `#r "MyAssembly.dll"`). For information on how to upload files to your function folder, see the following section on package management.
179
199
180
200
## Editor Prelude
181
-
An editor that supports F# Compiler Services will not be aware of the namespaces and assemblies that Azure Functions automatically includes. As such, it can be useful to include a prelude that helps the editor find the assemblies you are using, and to explicitly open namespaces. For example:
201
+
An editor that supports F# Compiler Services won't be aware of the namespaces and assemblies that Azure Functions automatically includes. As such, it can be useful to include a prelude that helps the editor find the assemblies you're using, and to explicitly open namespaces. For example:
182
202
183
203
```fsharp
184
204
#if !COMPILED
@@ -199,7 +219,7 @@ When Azure Functions executes your code, it processes the source with `COMPILED`
199
219
<aname="package"></a>
200
220
201
221
## Package management
202
-
To use NuGet packages in an F# function, add a `project.json` file to the function's folder in the function app's file system. Here is an example `project.json` file that adds a NuGet package reference to `Microsoft.ProjectOxford.Face` version 1.1.0:
222
+
To use NuGet packages in an F# function, add a `project.json` file to the function's folder in the function app's file system. Here's an example `project.json` file that adds a NuGet package reference to `Microsoft.ProjectOxford.Face` version 1.1.0:
203
223
204
224
```json
205
225
{
@@ -221,8 +241,8 @@ You may wish to put automatically references assemblies in your editor prelude,
221
241
222
242
### How to add a `project.json` file to your Azure Function
223
243
1. Begin by making sure your function app is running, which you can do by opening your function in the Azure portal. This also gives access to the streaming logs where package installation output will be displayed.
224
-
2. To upload a `project.json` file, use one of the methods described in [how to update function app files](functions-reference.md#fileupdate). If you are using [Continuous Deployment for Azure Functions](functions-continuous-deployment.md), you can add a `project.json` file to your staging branch in order to experiment with it before adding it to your deployment branch.
225
-
3. After the `project.json` file is added, you will see output similar to the following example in your function's streaming log:
244
+
2. To upload a `project.json` file, use one of the methods described in [how to update function app files](functions-reference.md#fileupdate). If you're using [Continuous Deployment for Azure Functions](functions-continuous-deployment.md), you can add a `project.json` file to your staging branch in order to experiment with it before adding it to your deployment branch.
245
+
3. After the `project.json` file is added, you'll see output similar to the following example in your function's streaming log:
226
246
227
247
```
228
248
2016-04-04T19:02:48.745 Restoring packages.
@@ -253,7 +273,7 @@ let Run(timer: TimerInfo, log: ILogger) =
0 commit comments