UriTemplate constructor

UriTemplate(
  1. String template
)

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.

Implementation

UriTemplate(this.template) : _variableNames = extractVariableNames(template), _pathRegex = buildRegex(template);