Hide Table of Contents
esri/dijit/util
esri/layer/pixelFilters
esri/process
esri/workers
Object: esri/urlUtils

require(["esri/urlUtils"], function(urlUtils) { /* code goes here */ });

Description

(Added at v3.8)
Utility methods for working with URLs.

When coding legacy (non-AMD) style, there is no need to require the module. All methods and properties are available in the namespace. For example, esri.addProxyRule().

Samples

Search for samples that use this class.

Methods

NameReturn typeSummary
addProxyRule(rule)NumberAdds the given proxy rule to the proxy rules list: esri.config.defaults.io.proxyRules.
getProxyRule()ObjectReturns the proxy rule that matches the given url. .
urlToObject(url)ObjectConverts the URL arguments to an object representation.
Method Details

addProxyRule(rule)

Adds the given proxy rule to the proxy rules list: esri.config.defaults.io.proxyRules
Return type: Number
Parameters:
<Object> rule Required The rule argument should have the following properties.
  • proxyUrl - URL for the proxy.
  • urlPrefix - URL prefix for resources that need to be accessed through the given proxy.

getProxyRule()

Returns the proxy rule that matches the given url.
Return type: Object

urlToObject(url)

Converts the URL arguments to an object representation. The object format is
{path: <String>, query:{key:<Object>}}
Return type: Object
Parameters:
<String> url Required The input URL.
Sample:
require([
  "esri/urlUtils", ... 
], function(urlUtils, ... ) {
  var myObject = urlUtils.urlToObject("http://www.myworld.com?state_name=Ohio&city_name=Akron");
  ...
});
Returns:
{ path: "http://www.myworld.com", query: {state_name: "Ohio", city_name: "Akron"} }

If there are no query parameters the return value for query will be null:

{path:"http://www.myworld.com",query:null}

The following snippet shows how to check for null or undefined values.

var myObject =  urlUtils.urlToObject("http://www.myworld.com");
if(myObject.query){
  var query = myObject.query;
}