How to parametrize the Azure Function

This short post should demonstrate how to parazmetrize the A\ure Function that is triggered by HTTP/S request.

For example, the caller uses following URL with two argyments and some optional route:

https://my-parametrized-func.azurewebsites.net/api/myoptionalroute/arg1/arg2?code=aEQ0z2qhuFfJd4AIfaXdfK2TzLSHSW95jXSay41eR0oMHbHywdQ9XQ==&clientId=default

The route is specified in bindings section:

"configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "route": "myoptionalroute/arg1/arg2",
      "methods": [
        "get"
      ],
      "authLevel": "function",
      "name": "req"
    }
  ],

Finally, the function should be decorated as shown in the following example:

[FunctionName("MyParametrizedFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, 
"get", Route = "myoptionalroute/{arg1}/{arg2}")] HttpRequest req, 
string policyHolder, string policyNumber, ILogger log)
{
            log.LogInformation($"PolicyDocs Function recieved a request for document '{policyHolder}-{policyNumber}.pdf'.");

}

comments powered by Disqus