Using the Azure Function return value

This article explains how return values work inside a function. In languages that have a return value, you can bind a function output binding to the return value.

Set the name property in function.json to $return. If there are multiple output bindings, use the return value for only one of them.

How return values are used depends on the C# mode you're using in your function app:

See Output bindings in the .NET worker guide for details and examples.

Here's the output binding in the function.json file:

{
    "name": "$return",
    "type": "blob",
    "direction": "out",
    "path": "output-container/{id}"
}

Here's the JavaScript code:

module.exports = function (context, input) {
    var json = JSON.stringify(input);
    context.log('Node.js script processed queue message', json);
    return json;
}

Here's the output binding in the function.json file:

{
    "name": "Response",
    "type": "blob",
    "direction": "out",
    "path": "output-container/{blobname}"
}

Here's the PowerShell code that uses the return value for an http output binding:

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $blobname
    })

Here's the output binding in the function.json file:

{
    "name": "$return",
    "type": "blob",
    "direction": "out",
    "path": "output-container/{id}"
}

Here's the Python code:

def main(input: azure.functions.InputStream) -> str:
    return json.dumps({
        'name': input.name,
        'length': input.length,
        'content': input.read().decode('utf-8')
    })

Apply the output binding annotation to the function method. If there are multiple output bindings, use the return value for only one of them.

Here's Java code that uses the return value for an output binding:

@FunctionName("QueueTrigger")
@StorageAccount("AzureWebJobsStorage")
@BlobOutput(name = "output", path = "output-container/{id}")
public static String run(
  @QueueTrigger(name = "input", queueName = "inputqueue") WorkItem input,
  final ExecutionContext context
) {
  String json = String.format("{ \"id\": \"%s\" }", input.id);
  context.getLogger().info("Java processed queue message. Item=" + json);
  return json;
}

Next steps