UriMatcher - Scoped

concept brazil Updated Sep 10, 2026 2 min read UriMatcherScopedAPI.md
Raw file servicenow.com

Provides a method to check if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.

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

This API is provided within the sn_ws namespace.

Parent Topic:Server API reference

UriMatcher - UriMatcher()

Instantiates a new UriMatcher object.

Name Type Description
None

Instantiates a UriMatcher object.

JavaScript
var matcher = new sn_ws.UriMatcher();

UriMatcher - match(String uri, String scheme, Array hosts, Array paths, Array fragments, Boolean disallowQueryParameters)

Checks if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.

Name

Type

Description

uri

String

URI to test against the specified criteria.

scheme

String

Protocol used in the URI.Valid values:

  • http
  • https

hosts

Array

List of allowed hosts in the URI.The URI must use one of the allowed hosts to be considered a match.

paths

Array

Optional. List of allowed paths in the URI.The URI must use one of the allowed paths to be considered a match, and the allowed path must be the full path used in the URI. For example, if the allowed path is /path1, a URI with the path /path1/more isn't considered a match.

Note: Paths must start with /.

Default: Any path is allowed.

fragments

Array

Optional. List of allowed fragments in the URI. The URI is considered a match even if it doesn't contain any of the allowed fragments. The URI is only considered not matching if it contains fragments that aren't in the allowed list.

Default: Any fragment is allowed.

disallowQueryParameters

Boolean

Optional. Flag that indicates whether query parameters are allowed in the URI.Valid values:

  • true: Query parameters aren't allowed. If query parameters are included in the URI, an error occurs.
  • false: Query parameters are allowed.

Default: false

|Type|Description| |----|-----------| |[UriMatcherResponse](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/brazil/markdown/api-reference/server-api-reference/UriMatcherResponseScopedAPI.md)|UriMatcherResponse object with methods for returning detailed information about the match.|

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

JavaScript
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:

Text
Is URI a match: true

This example checks if the URI matches the specified scheme, host, path, fragments, and presence of query parameters.

JavaScript
var uri = "https://example.com/path1/more";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("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());  gs.info("Error message: " + resp.getErrorMessages());

Output:

YAML
Is URI a match: trueIs scheme a match: trueIs host a match: trueIs path a match: trueIs fragment a match: trueError occurred: falseError message:
Search documentation
Search document titles and file paths on the brazil branch