replace static method
Replaces placeholders in the given path
using the provided params
map.
Example:
Map<String, String> params = {'param1': 'value1', 'param2': 'value2'};
String result = PathReplacer.replace('/path/{param1}/endpoint/{param2}', params);
// Result: '/path/value1/endpoint/value2'
Implementation
static String replace(String path, Map<String, String> params) {
return path.replaceAllMapped(RegExp(r'{(\w+)}'), (match) {
String key = match.group(1)!;
return params.containsKey(key) ? params[key]! : match.group(0)!;
});
}