{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":942,"path":"api-reference/server-api-reference/UriMatcherScopedAPI.md","title":"UriMatcher - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# UriMatcher- Scoped\n\nProvides a method to check if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.\n\nThe UriMatcher API requires the REST API Provider \\(com.glide.rest\\) plugin, which is activated by default.\n\nThis API is provided within the `sn_ws` namespace.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## UriMatcher - UriMatcher\\(\\)\n\nInstantiates a new UriMatcher object.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| ||\n\nInstantiates a UriMatcher object.\n\n```\nvar matcher = new sn_ws.UriMatcher();\n```\n\n## UriMatcher - match\\(String uri, String scheme, Array hosts, Array paths, Array fragments, Boolean disallowQueryParameters\\)\n\nChecks if a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.\n\n<table id=\"table_ejx_wjw_qdc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nuri\n\n</td><td>\n\nString\n\n</td><td>\n\nURI to test against the specified criteria.\n\n</td></tr><tr><td>\n\nscheme\n\n</td><td>\n\nString\n\n</td><td>\n\nProtocol used in the URI.Valid values:\n\n-   http\n-   https\n\n</td></tr><tr><td>\n\nhosts\n\n</td><td>\n\nArray\n\n</td><td>\n\nList of allowed hosts in the URI.The URI must use one of the allowed hosts to be considered a match.\n\n</td></tr><tr><td>\n\npaths\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. 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.\n\n**Note:** Paths must start with `/`.\n\nDefault: Any path is allowed.\n\n</td></tr><tr><td>\n\nfragments\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. 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.\n\nDefault: Any fragment is allowed.\n\n</td></tr><tr><td>\n\ndisallowQueryParameters\n\n</td><td>\n\nBoolean\n\n</td><td>\n\nOptional. Flag that indicates whether query parameters are allowed in the URI.Valid values:\n\n-   true: Query parameters aren't allowed. If query parameters are included in the URI, an error occurs.\n-   false: Query parameters are allowed.\n\nDefault: false\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|[UriMatcherResponse](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/UriMatcherResponseScopedAPI.md)|UriMatcherResponse object with methods for returning detailed information about the match.|\n\nThis example checks if the URI matches the specified scheme and host.\n\n```\nvar uri = \"https://example.com/path?q=query\";\nvar scheme = \"https\";  \nvar allowedHosts = [\"example.com\"];  \nvar matcher = new sn_ws.UriMatcher();  \nvar resp = matcher.match(uri, scheme, allowedHosts);  \n\ngs.info(\"Is URI a match: \" + resp.isMatch());\n```\n\nOutput:\n\n```\nIs URI a match: true\n```\n\nThis example checks if the URI matches the specified scheme, host, path, fragments, and presence of query parameters.\n\n```\nvar uri = \"https://example.com/path1/more\";\nvar scheme = \"https\";  \nvar allowedHosts = [\"example.com\", \"sample.com\"];  \nvar allowedPaths = [\"/path1/more\", \"/path2/less\"];  \nvar allowedFragments = [\"section1\", \"section2\"];  \nvar noQueryParams = true;\nvar matcher = new sn_ws.UriMatcher();  \nvar resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments, noQueryParams);  \n\ngs.info(\"Is URI a match: \" + resp.isMatch());  \ngs.info(\"Is scheme a match: \" + resp.isSchemeMatches());  \ngs.info(\"Is host a match: \" + resp.isHostMatches());  \ngs.info(\"Is path a match: \" + resp.isPathMatches());  \ngs.info(\"Is fragment a match: \" + resp.isFragmentMatches());\ngs.info(\"Error occurred: \" + resp.isError());  \ngs.info(\"Error message: \" + resp.getErrorMessages());\n```\n\nOutput:\n\n```\nIs URI a match: true\nIs scheme a match: true\nIs host a match: true\nIs path a match: true\nIs fragment a match: true\nError occurred: false\nError message:\n```\n\n"}}