expand method
Replaces all variable placeholders in the template with actual values
provided in the variables
map.
Throws a PathMatchingException
if any required variable is missing.
Example:
final template = UriTemplate('/docs/{section}/{page}');
final url = template.expand({'section': 'guide', 'page': 'intro'});
print(url); // /docs/guide/intro
Implementation
String expand(Map<String, String> variables) {
String expandedPath = template;
for (final varName in _variableNames) {
if (!variables.containsKey(varName)) {
throw UriPathMatchingException('Missing required URI template variable: $varName');
}
expandedPath = expandedPath.replaceAll('{$varName}', variables[varName]!);
}
return expandedPath;
}