UriTemplate class
A utility class for defining and working with URI templates that include
path variables (e.g., /users/{id}/orders/{orderId}
).
This class supports matching incoming paths against templates, extracting variable values, and expanding templates into full URIs given a variable map.
π§° Usage:
final template = UriTemplate('/users/{id}/orders/{orderId}');
final match = template.match('/users/42/orders/99');
print(match); // {id: 42, orderId: 99}
final expanded = template.expand({'id': '42', 'orderId': '99'});
print(expanded); // /users/42/orders/99
Use this class when you need structured path parsing in routers, dynamic endpoint generation, or URL normalization logic.
Constructors
- UriTemplate(String template)
-
A utility class for defining and working with URI templates that include
path variables (e.g.,
/users/{id}/orders/{orderId}
).
Properties
Methods
-
expand(
Map< String, String> variables) β String -
Replaces all variable placeholders in the template with actual values
provided in the
variables
map. -
match(
String path) β Map< String, String> ? - Matches a path string against the URI template and extracts values for declared path variables.
-
noSuchMethod(
Invocation invocation) β dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) β String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) β bool -
The equality operator.
inherited