On an HTTPTrigger can the Route value be set to an empty string?

Dijon Tiger 0 Reputation points
2024-08-14T19:38:38.81+00:00

In Azure Functions I have a host setup like the below:


{
  "version": "2.0",
  "logging": {
    ...
    }
  },
  "extensions": {
    "http": {
      "routePrefix": "api/test"
    }
  }
}

I want to setup an http trigger that will have an empty route, IE: the endpoint would be api/test/ No route appears to default to the function name and the docs are not conclusive if an empty string as route will work? Is there a way to achieve this?

Sample HttpTrigger:

[Function("HttpFunction")]
public IActionResult Run(
	// should be called with `api/test/`
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "")] HttpRequest req)
{
    return new OkObjectResult($"This was called with `api/test/`");
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,855 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DillanSimmons 1 Reputation point
    2024-08-28T23:30:17.0333333+00:00

    You can do the below which should work to set an empty route on an HttpTrigger

    Route = "{x:regex(^$)?}"
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.