Azure / Azure/azure-functions-host
HttpTrigger's Route precedence is different from ASP.NET Core behavior
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
It seems that when a route template is specified in HttpTrigger, the precedence is in alphabetical order, unlike the ASP.NET Core implementation.
When the following sample code is executed, it is generally expected that the "List" function will be executed when "/Products/List" is accessed, but in fact the "Details" function is always called.
```cs
public class Products
{
[Function(nameof(Details))]
public IActionResult Details(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "Products/{id}")] HttpRequest req,
string id)
{
return new OkObjectResult("Invoke Details function");
}
[Function(nameof(List))]
public IActionResult List(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "Products/List")] HttpRequest req)
{
return new OkObjectResult("Invoke List function");
}
}
```

The ASP.NET Core documentation explains precedence as follows I am not comfortable with the precedence of Azure Functions.
>For example, consider templates /Products/List and /Products/{id}. It would be reasonable to assume that /Products/List is a better match than /Products/{id} for the URL path /Products/List. This works because the literal segment /List is considered to have better precedence than the parameter segment /{id}.
- https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-7.0#route-template-precedence-and-endpoint-selection-order
Contributor guide
Research direction
Start by reproducing the Products sample with the two HttpTrigger routes and compare which function handles /Products/List. Trace the host's HttpTrigger route matching and precedence behavior; done means literal /Products/List selects List while /Products/{id} still handles parameterized paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100