You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The newly added "Path ordering" section introduces a detailed explanation of the URL ordering algorithm. It is important to ensure that the explanation is clear, unambiguous, and easy to follow, especially for users unfamiliar with the topic. Verify that the examples provided effectively illustrate the rules and steps described.
## Path ordering
Before attempting to [match](#pattern-matching) the incoming request to the various APIs deployed on Tyk to determine which route should be taken, Tyk will first place all the APIs in order. The order is important because the routing logic will compare the incoming request against each in turn until it finds a match (or returns `HTTP 404` if no match is found).
On receipt of an API request Tyk firstly creates a list of all APIs and then iterates through the list for each of the following steps:
1. APIs that don't have a custom domain defined are moved to the end of the list
2. Then among each section (custom domain/no custom domain) it will sort by listen path length (longer paths first)
- note that (dynamic) path parameters are not resolved at this stage so `/api/{category}/user` will rank higher than `/api/123/user`3. Then, for each listen path it will sort the endpoints using these rules:
- remove path parameters (dynamic segments) in the listen path - for example `/{id}` will be replaced with `/`- order by the number of segments (count of `/`) from most to least - e.g. `/api/user/profile` before `/api/user`- if two endpoints differ only by parameters, the non-parameterized goes first - e.g. `/api/user` before `/api/{userId}`- if two endpoints have the same number of segments, the longer path goes first - e.g. `/api/user-access` before `/api/user`- for equal length paths, lexicographical order is applied - e.g. `/api/aba` before `/api/abc`
Having created the ordered list, Tyk will attempt to match the request against the paths (patterns) in the list, starting from the top and moving down the list.
If a match is found, no further checks will be perfomed, so it is important to understand how Tyk orders the patterns to ensure there is no accidental routing to the wrong endpoint.
andyo-tyk
changed the title
[TT-12871] Add explanation of path ordering before pattern matching
[TT-12871, DX-1784] Add explanation of path ordering before pattern matching
Dec 20, 2024
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DX-1784
Preview Link
https://deploy-preview-5812--tyk-docs.netlify.app/docs/nightly/getting-started/key-concepts/url-matching/#pattern-ordering
Description
Adding explanation of URL ordering algorithm
PR Type
Documentation
Description
Changes walkthrough 📝
url-matching.md
Added detailed documentation on path ordering and URL matching.
tyk-docs/content/getting-started/key-concepts/url-matching.md
Tyk orders APIs and endpoints.