getPatternUrlOrOriginal method

String getPatternUrlOrOriginal(
  1. String url
)

Matches a url against configured patterns and returns the pattern if matched.

For example, if /users/{id} is configured, /users/123 will return /users/{id}. If no pattern matches, the original url is returned.

Implementation

String getPatternUrlOrOriginal(String url) {
  if (_urlPatterns == null || _urlPatterns!.isEmpty) {
    return url;
  }

  // Extract path from URL (remove protocol, host, port, query params)
  Uri uri = Uri.parse(url);
  String path = uri.path;

  for (String pattern in _urlPatterns!) {
    if (_matchesPattern(path, pattern)) {
      return pattern;
    }
  }

  return url; // Return original URL if no pattern matches
}