Routes Definition
Basic Route
A basic route is a simple, static path:
Parameterized Route
To include parameters like a username or ID in the URL:
Regular Expression Constraints
You can add regex constraints to your parameters:
Optional Parameters
You can define routes with optional segments:
Complex Routes
You can also define more complex routes with multiple parameters:
Enumerated Parameters
For when you have a specific set of acceptable parameter values:
Shortcuts
For convenience, Router
offers shortcut methods for common HTTP request methods.
You can use these shortcut methods just like you would use the route method, but without the need to specify the HTTP method as the first argument.
The router only facilitates matching HEAD
requests to GET
routes when a specific HEAD
handler is not found.
Developers must explicitly ensure that HEAD
method calls always return empty response bodies.