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:

  • In a C# class library, apply the output binding attribute to the method return value.
  • In Java, apply the output binding annotation to the function method.
  • In other languages, set the name property in function.json to $return.

If there are multiple output bindings, use the return value for only one of them.

In C# and C# script, alternative ways to send data to an output binding are out parameters and collector objects.

Here's C# code that uses the return value for an output binding, followed by an async example:

[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static string Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
    string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
    log.LogInformation($"C# script processed queue message. Item={json}");
    return json;
}
[FunctionName("QueueTrigger")]
[return: Blob("output-container/{id}")]
public static Task<string> Run([QueueTrigger("inputqueue")]WorkItem input, ILogger log)
{
    string json = string.Format("{{ \"id\": \"{0}\" }}", input.Id);
    log.LogInformation($"C# script processed queue message. Item={json}");
    return Task.FromResult(json);
}

Next steps