-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add pattern-based routing implemented as web.Routes #111
Open
thekid
wants to merge
28
commits into
master
Choose a base branch
from
feature/pattern-based-routing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request refactors the
web.Routes
class to use regular expressions for routing. The new implementation comes with decreased complexity and increased performance (by not delegating to a variety of method calls) while sacrificing a completely flexible way of routing requests by using matcher functions, while adding the possibility to route patterns.Route patterns
...are essentially regular expressions, with the small difference that
.
matches its literal form and that the^
and$
metacharacters cannot be used due to how the patterns are constructed. If you want to match a single character use\C
instead.Here are a couple of examples:
Paths
/(favicon.ico|robots.txt)
matches the files favicon.ico and robots.txt (but not favicon_ico, which a regular expression would match)/(?i)test.html
using the internal-option syntax matches the file test.html in any case/users/[a-z]+
matches /users/test but not /users/0815.Restricting to methods
GET|POST /users
matches GET and POST requests to /usersHEAD /
andHEAD
both match HEAD requests to the root path.Route patterns are matched against
/[PATH]
or[METHOD] /[PATH]
if they do not start with forward slash.Placeholders
Enclosed in curly braces:
/users/{id}
will match any path segment and pass it as request value "id"/users/{id:[a-z]+}
will match lowercase letters and pass them as request value "id"Nested routes
This pull request enables nested routes by using maps:
Compacting
With route patterns, the following typical routing definition can be rewritten in a more compact way:
Fluent API
Instead of returning an array, a fluent style can be used:
Routing deprecation
This pull request also deprecates the
web.Routing
implementation and theweb.routing
package, both of which will be removed in the upcoming major release.This affects the following types:
See also