Search code examples
c#azure-functionsurl-routingazure-http-trigger

Azure functions - Map empty string as route for a function


Is there a way to map empty string as route to an Azure Function. Like lets say when I hit the https://example.org/api (empty string), the function will be hit. I have tried like below, but it did not work.

[FunctionName("Default")]
public static async Task<IActionResult> Run(
   [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "")] HttpRequest req,
    ILogger log)
{
       ...
}

Solution

  • Turns out there is no direct way to do it. PFB the screenshot with the error message picked from the console after running Functions solution. Functions route must be non-empty

    However, it can be achieved using Function proxy. Add the below json to your proxies.json. So, this way lets say you are hitting "http://localhost:7071/api/" it will land on your specified function.

    {
      "proxies": {
        "EmptyRouteProxy": {
          "matchCondition": {
            "route": "/"
          },
          "backendUri": "http://localhost:7071/api/SampleFunc"
        }
      }
    }