suraj_123
suraj_123

Reputation: 169

How to get azure function URL at runtime C#

Is it possible to get azure function URL (at runtime) for Http triggered function app developed in C#.I have implemented a health check for function app.I need to call function URL to check whether the function is healthy or not . I know azure provide services to check FA health but I need to implement as per organization standards. So, Basically it will be a endpoint /healthCheck to get health report.

Upvotes: 0

Views: 3713

Answers (2)

silent
silent

Reputation: 16208

While I don't understand yet what you are trying to do (and if that is a good idea..) you can infer your function URL through the pre-set env var WEBSITE_HOSTNAME (assuming you are not using a custom domain):

var url = $"https://{Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME")}/api/YOURFUNCTIONNAME";

Upvotes: 1

Harshita Singh
Harshita Singh

Reputation: 4870

I do not see a need of getting runtime Azure function app URLs as they remain the same always after creation. On the same lines, you can automate your Function Apps using ARM templates.

And, use the created URLs defined in your endpoint's configuration and use them in your code from the configuration. For example, if you are using App Service, you can save those values in App Settings and read them like below:

var value = Environment.GetEnvironmentVariable("your_key_here");

Upvotes: 0

Related Questions