Howiecamp Howiecamp - 3 months ago 51
C# Question

How to set up HTTP outputs in Azure Functions

I've got a simple Azure function for which I set up a DocumentDB output (as an example):

Azure Functions DocumentDB output screenshot

I then added the

outputDocument
parameter to the function and assigned a value to it in the code (by the way I was surprised that when I set up the output that the runtime didn't automatically modify the function signature):

using System;

public static void Run(string input, out object outputDocument, TraceWriter log)
{
log.Info($"C# manually triggered function called with input: {input}");

outputDocument = new {
text = $"I'm running in a C# function! {input}"
};
}


When I run the function the Azure Functions runtime does it's binding magic and the DocumentDB document gets created.

I then set up an HTTP output:

Azure Functions HTTP output

and defined the
res
output parameter.

But now what? What's the process of assigning to res? I've of course got to define the destination, request type, parms, etc.

Answer

Howiecamp,

The HTTP output binding works in conjunction with the HTTP Trigger to act as the response handler for an HTTP request.

Currently, there isn't an output binding that would send the output payload over HTTP for you, so you'd need to make that HTTP request from your function code (e.g. using the HttpClient and issuing the request). You can see an example in one of our templates here: https://github.com/Azure/azure-webjobs-sdk-templates/blob/10650dbf9c4bad75b0c89b9c355edc53fe913cde/Templates/GitHubCommenter-CSharp/run.csx#L40-L49

I hope this helps!

Comments