// request GeoJson data from USGS remote server
var url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson";
esriRequest(url, {
responseType: "json"
}).then(function(response){
// The requested data
var geoJson = response.data;
});
Method Overview
Name | Return Type | Summary | |
---|---|---|---|
Promise | Retrieves data from a remote server or uploads a file from a user's computer. more details | more details |
Method Details
esriRequest(url, options){Promise}
Retrieves data from a remote server or uploads a file from a user's computer.
Parameters:url StringThe request URL.
optionaloptions ObjectAn object with the following properties that describe the request.
Specification:optionalcallbackParamName StringName of the callback parameter (a special service parameter) to be specified when requesting data in JSONP format. It is ignored for all other data formats. For ArcGIS services the value is always
callback
.optionalquery ObjectIf the request URL points to a web server that requires parameters, specify them here.
Default Value: nulloptionalresponseType StringResponse format. When this value is
image
themethod
andtimeout
options are ignored.
Possible Values: json | xml | text | blob | array-buffer | document | image
Default Value: jsonoptionalheaders ObjectHeaders to use for the request. This is an object whose property names are header names. This is not applicable for non-XHR requests.
optionaltimeout NumberIndicates the amount of time in milliseconds to wait for a response from the server. Set to
0
to wait for the response indefinitely. This option is ignored whenresponseType = "image"
.
Default Value: 60000optionalmethod StringIndicates if the request should be made using the HTTP POST method. By default, this is determined automatically based on the request size. This option is ignored when
responseType = "image"
.
Known Values: auto | post
Default Value: autooptionalbody FormData | HTMLFormElement | StringIf uploading a file, specify the form data or element used to submit the file here. If a form element is specified, the parameters of the
query
will be added to the URL. If not specified, then query parameters will only be added to the URL when a GET request is used. If POST is used, then query parameters will be added to the body.optionaluseProxy BooleanIndicates the request should use the proxy. By default this is determined automatically based on the domain of the request url.
Default Value: falseoptionalcacheBust BooleanIndicates whether to send an extra query parameter to ensure the server doesn't supply cached values.
Default Value: falseoptionalallowImageDataAccess BooleanIndicates whether apps are allowed to read image data (when used with Canvas) from images hosted on third-party sites. Only applicable when
responseType = "image"
.
Default Value: falseReturns:Type Description Promise Returns a promise that resolves to an object with the following specification.
The requested response types and their corresponding return types are described in the table below.Property Type Description data * The requested data. See the table below to match the responseType with the data return type. requestOptions Object The options specified by the user in the data request. This has the same specification as the options
object defined in the request parameters above.url String The URL used to request the data. getHeader() getHeader Method for getting a header sent from the server. responseType Return type Description json Object The requested data object. xml XMLDocument The requested XML document. text String The requested text. blob Blob The requested blob. array-buffer ArrayBuffer The requested ArrayBuffer. document HTMLDocument The requested HTML document. image HTMLImageElement The requested image. Example:// request GeoJson data from USGS remote server var url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson"; esriRequest(url, { responseType: "json" }).then(function(response){ // The requested data var geoJson = response.data; });
Type Definitions
getHeader(headerName){String}
A function to retrieve headers sent from the server. This is ignored for
jsonp
requests.Parameter:headerName StringThe name of the header.
Returns:Type Description String The header value. Example:esriRequest(url, options).then(function(response) { var responseJSON = JSON.stringify(response, null, 2); // prints the content type of the request: 'application/json' console.log("header: ", response.getHeader('Content-Type')); });