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

hashCode β†’ int
The hash code for this object.
no setterinherited
runtimeType β†’ Type
A representation of the runtime type of the object.
no setterinherited
template β†’ String
The raw URI template string.
final

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

Static Methods

matches(String first, String second) β†’ bool
Matches two urls to each other
normalize(String url) β†’ String
Produces a normalized version of a full URL string by applying various standardizations:
normalizePath(String path) β†’ String
Normalizes a raw path by: