2

In an HTTP triggered azure function we can get the url as follows

public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, Microsoft.Azure.WebJobs.ExecutionContext executionContext, ILogger log)
{
    string url = req.Scheme + "://" + req.Host + $"/api/AnotherFunctionOnTheApp";
}

But how do we do it in an event grid triggered function where we do not have the HTTPRequest object?

public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
{
    
}

The objective is to call an HTTP triggered function on the same functionapp from the event grid triggered function.

dushyantp
  • 4,398
  • 7
  • 37
  • 59

1 Answers1

2

A simple example to get the url of the httptrigger:

string url = "https://" + Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME") + "/api/AnotherFunctionOnTheApp";

(Azure will offer a secure domain by default. So we can use 'https'.)

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • 1
    Thanks, this works. Only difference is I am using #if DEBUG string httpScheme = "http://"; #else string httpScheme = "https://"; #endif So that postman call the function locally for debugging. – dushyantp Nov 11 '20 at 08:31