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
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.
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.
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.
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With