Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 611
Howiecamp Avatar asked Aug 27 '16 19:08

Howiecamp


People also ask

Can you trigger an Azure function using an HTTP request?

Azure Functions may be invoked via HTTP requests to build serverless APIs and respond to webhooks.

Can Azure functions receive web requests?

Azure Functions is a serverless service from Microsoft that allows us to write blocks of code called functions that run in response to an event, such as an HTTP request or IoT event.


1 Answers

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!

like image 106
Fabio Cavalcante Avatar answered Oct 14 '22 13:10

Fabio Cavalcante