0

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)
{
       ...
}
sprash95
  • 137
  • 9

2 Answers2

0

Customize the HTTP endpoint:

By default, all function routes are prefixed with api. You can also customize or remove the prefix using the extensions.http.routePrefix property in your host.json file. The following example removes the api route prefix by using an empty string for the prefix in the host.json file.

# host.json

{
    "extensions": {
        "http": {
            "routePrefix": ""
        }
    }
}
Max Ivanov
  • 5,695
  • 38
  • 52
0

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"
    }
  }
}
sprash95
  • 137
  • 9