Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize Azure function url

Just got started with azure functions. I am using it as an httptrigger for an IoT device.

I am trying to setup one function that will work for httptrigger requests coming from several IoT devices - So I dont have to setup one function per device. So ideally, in my c# file, I will have something like this:

DeviceClient deviceClient;
string iotHubUri = "myhub";
string deviceName = "something dynamic here that changes with device";
string deviceKey = "something dynamic here that changes with device";

Then , I'd like to get my function url to look something like this:

"https://<functionapp>.azurewebsites.net/api/<function>/{device_id}?code=xxxxx"

where device_id is the IoT device id.

I am not sure how to first setup the reference in the c# file to be dynamic and also how to get the url to look the way I intend.

Some help will be appreciated. Thanks

like image 797
user2022284 Avatar asked Jan 31 '18 14:01

user2022284


People also ask

How do I edit my Azure function app?

The Functions editor built into the Azure portal lets you update your function code and configuration (function. json) files directly in the portal. Select your function app, then under Functions select Functions. Choose your function and select Code + test under Developer.

Can Azure Functions act as a Webhook?

Webhooks offer a lightweight mechanism for your app to be notified by another service when something of interest happens. In this module. you'll learn how to trigger an Azure function with a GitHub webhook and parse the payload for insights.

What is HTTP trigger in Azure function?

The HTTP trigger lets you invoke a function with an HTTP request. You can use an HTTP trigger to build serverless APIs and respond to webhooks. The default return value for an HTTP-triggered function is: HTTP 204 No Content with an empty body in Functions 2.

Can we rename Azure function app?

Renaming an Azure function:To rename it we first need to click on the “Platform features”. Closer to the bottom, which says “Development Tools,” we need to select “Console.” Now, because this Azure function is being hosted on a Windows machine, We can get access to the Windows command line.


1 Answers

There is a route parameter is HTTP trigger exactly for this. Your trigger definition should look something like this:

"bindings": [
  {
    "type": "httpTrigger",
    "route": "something/{deviceid}",
    "name": "request",
    // possibly other parameters
  }
],

If you are using precompiled C# functions, you can do the same via attribute property, e.g.

public static IActionResult Run(
    [HttpTrigger(AuthorizationLevel.Function, "GET", Route = "something/{deviceid}")] 
    HttpRequest request,
    string deviceid)
{
    // do something based on device id
}
like image 199
Mikhail Shilkov Avatar answered Oct 14 '22 01:10

Mikhail Shilkov