Different Routes in Azure Functions

Viewed 8204


I am using Azure Functions and I want to create a Function that should react to multiple routes. For example "/path1/{param1}" and "/path2/xxx/{param2}" or something like this.
Does anybody know how can I implement this?

3 Answers

As indicated by @Naren, the Azure functions route parameter is actually used as an ASP.NET route in the backend. This means that we can also take advantage of optional parameters to provide essentially the same behavior that you want. This is a useful alternative for a variety of things if you don't want to use Function Proxies.

Set the route to:

/{path:regex(^path[12]$)}/{param1}/{param2?}

Because param2 is optional, if you call /path2/blah you will just get null for the value of param2. To ensure that only xxx can be used for param1 when path == "path1", you can just do a simple check in your code.

Related