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?
- 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
1 Answer
Reset to default 0Without 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!");
}
本文标签:
版权声明:本文标题:How can I make all Azure Functions routes lowercase without using Route parameter on every function definition? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736312410a1935084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论