{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":941,"path":"api-reference/server-api-reference/UriMatcherResponseScopedAPI.md","title":"UriMatcherResponse - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# UriMatcherResponse- Scoped\n\nProvides methods to return information about whether a URI matches specified criteria for scheme, host, path, fragments, and presence of query parameters.\n\nUse this API with the UriMatcher API. This API doesn't have a constructor. Instead, use the [UriMatcher - match\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/UriMatcherScopedAPI.md) method to instantiate a UriMatcherResponse object.\n\nThe UriMatcherResponse 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## UriMatcherResponse - getErrorMessages\\(\\)\n\nReturns messages about any errors that occurred when testing the URI against the specified criteria.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Description of the error that occurred. If no error occurred, an empty string is returned.|\n\nThis example returns an error because a host wasn't provided in the matching criteria.\n\n```\nvar uri = \"https://example.com\";\nvar scheme = \"https\";    \nvar matcher = new sn_ws.UriMatcher();  \nvar resp = matcher.match(uri, scheme);  \n\ngs.info(\"Error occurred: \" + resp.isError());  \ngs.info(\"Error message: \" + resp.getErrorMessages());\n```\n\nOutput:\n\n```\nError occurred: true\nError message: Hosts rule is null or empty.\n```\n\n## UriMatcherResponse - isError\\(\\)\n\nChecks if an error occurred when testing the URI against the specified criteria.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_nh3_xyt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether an error occurred.\n\n Valid values:\n\n-   true: An error occurred.\n-   false: No errors occurred.\n\n</td></tr></tbody>\n</table>This example returns an error because the URI contains query parameters. The error occurs because the argument passed to match\\(\\) for **disallowQueryParameters** is `true`.\n\n```\nvar uri = \"https://example.com/path1/more?q=query\";\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(\"Error occurred: \" + resp.isError());  \ngs.info(\"Error message: \" + resp.getErrorMessages());\n```\n\nOutput:\n\n```\nError occurred: true\nError message: Query parameters are not allowed for matching.\n```\n\n## UriMatcherResponse - isFragmentMatches\\(\\)\n\nChecks if the URI matches the criteria for fragments.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_wls_lzt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the URI matches the criteria for fragments.\n\n Valid values:\n\n-   true: The URI matches the criteria for fragments.\n-   false: The URI doesn't match the criteria for fragments.\n\n</td></tr></tbody>\n</table>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.\n\n```\nvar uri = \"https://example.com/path1/more#section3\";\nvar scheme = \"https\";  \nvar allowedHosts = [\"example.com\", \"sample.com\"];  \nvar allowedPaths = [\"/path1/more\", \"/path2/less\"];  \nvar allowedFragments = [\"section1\", \"section2\"];  \nvar matcher = new sn_ws.UriMatcher();  \nvar resp = matcher.match(uri, scheme, allowedHosts, allowedPaths, allowedFragments);  \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());\n```\n\nOutput:\n\n```\nIs URI a match: false\nIs scheme a match: true\nIs host a match: true\nIs path a match: true\nIs fragment a match: false\nError occurred: false\n```\n\n## UriMatcherResponse - isHostMatches\\(\\)\n\nChecks if the URI matches the criteria for the host.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_jgl_hzt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the URI matches the criteria for the host.\n\n Valid values:\n\n-   true: The URI matches the criteria for the host.\n-   false: The URI doesn't match the criteria for the host.\n\n</td></tr></tbody>\n</table>This 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());\ngs.info(\"Is host a match: \" + resp.isHostMatches());\n```\n\nOutput:\n\n```\nIs URI a match: true\nIs host a match: true\n```\n\n## UriMatcherResponse - isMatch\\(\\)\n\nChecks if the URI matches all of the specified criteria.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_hzs_tyt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the URI matches all of the specified criteria.\n\n Valid values:\n\n-   true: The URI matches all of the criteria.\n-   false: The URI doesn't match all of the criteria.\n\n</td></tr></tbody>\n</table>This 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\n## UriMatcherResponse - isPathMatches\\(\\)\n\nChecks if the URI matches the criteria for the path.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_b5x_3zt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the URI matches the criteria for the path.\n\n Valid values:\n\n-   true: The URI matches the criteria for the path.\n-   false: The URI doesn't match the criteria for the path.\n\n</td></tr></tbody>\n</table>This example checks if the URI matches the specified scheme, host, and path.\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 matcher = new sn_ws.UriMatcher();  \nvar resp = matcher.match(uri, scheme, allowedHosts, allowedPaths);  \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());\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\n```\n\n## UriMatcherResponse - isSchemeMatches\\(\\)\n\nChecks if the URI matches the criteria for the scheme.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_q54_dzt_rdc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the URI matches the criteria for the scheme.\n\n Valid values:\n\n-   true: The URI matches the criteria for the scheme.\n-   false: The URI doesn't match the criteria for the scheme.\n\n</td></tr></tbody>\n</table>This 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());\ngs.info(\"Is scheme a match: \" + resp.isSchemeMatches());\n```\n\nOutput:\n\n```\nIs URI a match: true\nIs scheme a match: true\n```\n\n"}}