Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

order HTTP routes in a logical way #842

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

briandunnington
Copy link
Contributor

Consider two routes:

/api/recent
/api/{id}

Currently, Azure Functions orders routes by the alphabetical order of the function name, so it is non-deterministic as to which route will be choosen if a request for '/api/recent' comes in depending on the names of the functions.

This PR makes the order deterministic and sensible. It prefers static segments over parameterized segments (will always pick '/api/recent' for a request of '/api/recent' even though '/api/{id}' is also a match) and prefers more-specific (longer) routes over less-specific (shorter) routes if everything else is the same.

Addresses:
Azure/azure-functions-host#3153
Azure/azure-functions-core-tools#2442
Azure/azure-functions-host#3152
MicrosoftDocs/azure-docs#11755

cc @fabiocav

@karstenjMSFT
Copy link

Please consider this PR. It dramatically improves the logic of how functions handles routes. The PR has been open since April!

@grantborthwick
Copy link

grantborthwick commented Feb 14, 2024

Any progress on this? Our team would use this - our use case is that we have multiple routes defined, but also need to add a route at the root of the cname and want the more specific routes to take precedence over a wildcard match at the root. Either this or supporting Order on the HttpTriggerAttribute would support this scenario. Otherwise, we're implementing our own custom logic to route to sub-paths in a single function at the root.

Just also found this note that states that routes are considered alphabetically by FunctionName - Azure/azure-functions-host#3153 (comment) - this should work for our scenario by prefixing the function with z_.

@pregress
Copy link

Could also use this in the workers SDK...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants