UriMatcherResponse - Scoped

  • Release version: Zurich
  • Updated July 31, 2025
  • 4 minutes to read
  • Provides methods to return information about whether a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.

    Use this API with the UriMatcher API. This API doesn't have a constructor. Instead, use the UriMatcher - match() method to instantiate a UriMatcherResponse object.

    The UriMatcherResponse API requires the REST API Provider (com.glide.rest) plugin, which is activated by default.

    This API is provided within the sn_ws namespace.

    UriMatcherResponse - getErrorMessages()

    Returns messages about any errors that occurred when testing the URI against the specified criteria.

    Table 1. Parameters
    Name Type Description
    None
    Table 2. Returns
    Type Description
    String Description of the error that occurred. If no error occurred, an empty string is returned.

    This example returns an error because a host wasn't provided in the matching criteria.

    var uri = "https://example.com";
    var scheme = "https";    
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme);  
    
    gs.info("Error occurred: " + resp.isError());  
    gs.info("Error message: " + resp.getErrorMessages());

    Output:

    Error occurred: true
    Error message: Hosts rule is null or empty.

    UriMatcherResponse - isError()

    Checks if an error occurred when testing the URI against the specified criteria.

    Table 3. Parameters
    Name Type Description
    None
    Table 4. Returns
    Type Description
    Boolean

    Flag that indicates whether an error occurred.

    Valid values:
    • true: An error occurred.
    • false: No errors occurred.

    This example returns an error because the URI contains query parameters. The error occurs because the argument passed to match() for disallowQueryParameters is true.

    var uri = "https://example.com/path1/more?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var allowedFragments = ["section1", "section2"];  
    var noQueryParams = true;
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments, noQueryParams);  
    
    gs.info("Error occurred: " + resp.isError());  
    gs.info("Error message: " + resp.getErrorMessages());

    Output:

    Error occurred: true
    Error message: Query parameters are not allowed for matching.

    UriMatcherResponse - isFragmentMatches()

    Checks if the URI matches the criteria for fragments.

    Table 5. Parameters
    Name Type Description
    None
    Table 6. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for fragments.

    Valid values:
    • true: The URI matches the criteria for fragments.
    • false: The URI doesn't match the criteria for fragments.

    This example shows that the URI doesn't match the criteria because it contains a fragment that isn't in the list of allowed fragments.

    var uri = "https://example.com/path1/more#section3";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var allowedFragments = ["section1", "section2"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments);  
    
    gs.info("Is URI a match: " + resp.isMatch());  
    gs.info("Is scheme a match: " + resp.isSchemeMatches());  
    gs.info("Is host a match: " + resp.isHostMatches());  
    gs.info("Is path a match: " + resp.isPathMatches());  
    gs.info("Is fragment a match: " + resp.isFragmentMatches());
    gs.info("Error occurred: " + resp.isError());

    Output:

    Is URI a match: false
    Is scheme a match: true
    Is host a match: true
    Is path a match: true
    Is fragment a match: false
    Error occurred: false

    UriMatcherResponse - isHostMatches()

    Checks if the URI matches the criteria for the host.

    Table 7. Parameters
    Name Type Description
    None
    Table 8. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the host.

    Valid values:
    • true: The URI matches the criteria for the host.
    • false: The URI doesn't match the criteria for the host.

    This example checks if the URI matches the specified scheme and host.

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());
    gs.info("Is host a match: " + resp.isHostMatches());

    Output:

    Is URI a match: true
    Is host a match: true

    UriMatcherResponse - isMatch()

    Checks if the URI matches all of the specified criteria.

    Table 9. Parameters
    Name Type Description
    None
    Table 10. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches all of the specified criteria.

    Valid values:
    • true: The URI matches all of the criteria.
    • false: The URI doesn't match all of the criteria.

    This example checks if the URI matches the specified scheme and host.

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());

    Output:

    Is URI a match: true

    UriMatcherResponse - isPathMatches()

    Checks if the URI matches the criteria for the path.

    Table 11. Parameters
    Name Type Description
    None
    Table 12. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the path.

    Valid values:
    • true: The URI matches the criteria for the path.
    • false: The URI doesn't match the criteria for the path.

    This example checks if the URI matches the specified scheme, host, and path.

    var uri = "https://example.com/path1/more";
    var scheme = "https";  
    var allowedHosts = ["example.com", "sample.com"];  
    var allowedPaths = ["/path1/more", "/path2/less"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts, allowedPaths);  
    
    gs.info("Is URI a match: " + resp.isMatch());  
    gs.info("Is scheme a match: " + resp.isSchemeMatches());  
    gs.info("Is host a match: " + resp.isHostMatches());  
    gs.info("Is path a match: " + resp.isPathMatches());  
    gs.info("Is fragment a match: " + resp.isFragmentMatches());
    gs.info("Error occurred: " + resp.isError());

    Output:

    Is URI a match: true
    Is scheme a match: true
    Is host a match: true
    Is path a match: true
    Is fragment a match: true
    Error occurred: false

    UriMatcherResponse - isSchemeMatches()

    Checks if the URI matches the criteria for the scheme.

    Table 13. Parameters
    Name Type Description
    None
    Table 14. Returns
    Type Description
    Boolean

    Flag that indicates whether the URI matches the criteria for the scheme.

    Valid values:
    • true: The URI matches the criteria for the scheme.
    • false: The URI doesn't match the criteria for the scheme.

    This example checks if the URI matches the specified scheme and host.

    var uri = "https://example.com/path?q=query";
    var scheme = "https";  
    var allowedHosts = ["example.com"];  
    var matcher = new sn_ws.UriMatcher();  
    var resp = matcher.match(uri, scheme, allowedHosts);  
    
    gs.info("Is URI a match: " + resp.isMatch());
    gs.info("Is scheme a match: " + resp.isSchemeMatches());

    Output:

    Is URI a match: true
    Is scheme a match: true