Basic Routes
Routes are registered using HTTP method functions on the App instance:Route Parameters
Route parameters are dynamic path segments that capture values from the URL. They are defined using the: prefix:
Optional Parameters
Make parameters optional by adding a? suffix:
Wildcard Routes
Wildcard parameters match one or more path segments:Asterisk Wildcard (*)
The * wildcard is optional and matches zero or more segments:
Plus Wildcard (+)
The + wildcard is required and matches one or more segments:
Parameter Constraints
Constrain parameter values using type validation:Available Constraints
| Constraint | Description | Example |
|---|---|---|
int | Integer values | :id<int> |
bool | Boolean values | :active<bool> |
float | Float values | :price<float> |
alpha | Alphabetic characters | :name<alpha> |
guid | GUID/UUID format | :uuid<guid> |
minLen(n) | Minimum length | :code<minLen(5)> |
maxLen(n) | Maximum length | :code<maxLen(10)> |
len(n) | Exact length | :code<len(8)> |
min(n) | Minimum value | :age<min(18)> |
max(n) | Maximum value | :age<max(100)> |
range(min,max) | Value range | :port<range(1024,65535)> |
regex(pattern) | Custom regex | :slug<regex(^[a-z0-9-]+$)> |
datetime(format) | Date/time format | :date<datetime(2006-01-02)> |
Multiple HTTP Methods
Register a route for multiple HTTP methods:Named Routes
Assign names to routes for easy reference:Route Configuration
Control routing behavior with application config:Case Sensitivity
By default, routes are case-insensitive:Strict Routing
By default, trailing slashes are optional:Route Matching Order
Routes are matched in the order they are defined. More specific routes should be defined before generic ones:Route Pattern Matching
Test if a path matches a route pattern without registering the route:Best Practices
Order routes from specific to generic
Order routes from specific to generic
Define specific routes before wildcard or parameter routes to ensure correct matching.
Use parameter constraints
Use parameter constraints
Add constraints to validate parameters early and improve route matching performance.
Name important routes
Name important routes
Use named routes for routes that are frequently referenced in redirects or links.
Group related routes
Group related routes
See Also
Grouping
Organize routes with common prefixes
Middleware
Add logic before/after route handlers
Context
Access request parameters and data
Error Handling
Handle routing errors gracefully