admin管理员组

文章数量:1122818

Consider the following Azure Function definition:

[Function(nameof(GetHealth))]
public async Task<IActionResult> GetHealth(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequestData req,
    FunctionContext context,
    CancellationToken cancellationToken)

Without the Route parameter, it would result in an endpoint route called /api/GetHealth when run.

Is there a way to make all endpoint routes lowercase without having to use Route parameter for every function definition?

Consider the following Azure Function definition:

[Function(nameof(GetHealth))]
public async Task<IActionResult> GetHealth(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequestData req,
    FunctionContext context,
    CancellationToken cancellationToken)

Without the Route parameter, it would result in an endpoint route called /api/GetHealth when run.

Is there a way to make all endpoint routes lowercase without having to use Route parameter for every function definition?

Share Improve this question edited Nov 21, 2024 at 13:14 Shuzheng asked Nov 21, 2024 at 8:41 ShuzhengShuzheng 13.7k28 gold badges113 silver badges224 bronze badges 1
  • You can try to rename it using this article on how to do it and create a small script for all:roykim.ca/2023/02/25/… – D A Commented Nov 21, 2024 at 9:00
Add a comment  | 

1 Answer 1

Reset to default 0

Without the Route parameter, it would result in an endpoint route called /api/GetHealth when run.

  • Yes, Indeed. You can pass the routePrefix as api/health in host.json file but it will also amend the function name at the end of the URL like api/health/GetHealth.
{
    "version": "2.0",
    "extensions": {
        "http": {
            "routePrefix": "api/health"
        }
    }
}
  • If you will add routes without using Route property in function signature then it will consider it as a Http method, resulting GetHealth: [GET,HEALTH] http://localhost:7174/api/GetHealth.

  • Hence, you need to add the Route property explicitly if you want to provide routes to the endpoint. Refer to Customize the HTTP endpoint in Azure Function which says below,

You can customize the route using the optional route property on the HTTP trigger's input binding.

  • So, you can pass the routes in lowercase as given below-
[Function("GetHealth")]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "health")] HttpRequest req)
{
    _logger.LogInformation("C# HTTP trigger function processed a request.");
    return new OkObjectResult("Welcome to Azure Functions!");
}

本文标签: