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

Dijon Tiger 10 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.


2 answers

Sort by: Most helpful
  1. DillanSimmons 41 Reputation points Admin
    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(^$)?}"
    

    Was this answer helpful?

    100+ people found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

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