request
require(["esri/request"], function(esriRequest) { /* code goes here */ });
esri/request
Retrieves data from a remote server or uploads a file.
// 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 | Function | |
---|---|---|---|---|
esriRequest() | Promise<RequestResponse> | Retrieves data from a remote server or uploads a file from a user's computer. more details | more details | request |
Method Details
- esriRequest(url, options){Promise<RequestResponse>}
Retrieves data from a remote server or uploads a file from a user's computer. If the request returns an Error, the error object will include the details specified in EsriErrorDetails.
Parameters:url StringThe request URL.
options RequestOptionsoptionalAn object with the following properties that describe the request.
Returns:Type Description Promise<RequestResponse> Returns a promise that resolves to an object with the following specification. If the request returns an Error, the error object will include the details specified in EsriErrorDetails.
Type Definitions
An object with the following properties that describe the request.
- Properties:
- optionalcallbackParamName String
Name 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 ObjectDefault Value:nullIf the request URL points to a web server that requires parameters, specify them here.
optionalresponseType StringDefault Value:jsonResponse format. When this value is
image
themethod
andtimeout
options are ignored.Possible Values: json | xml | text | blob | array-buffer | document | image
optionalheaders 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 NumberDefault Value:60000Indicates 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"
.optionalmethod StringDefault Value:autoIndicates 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"
.Possible Values: auto | post
optionalbody 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 BooleanDefault Value:falseIndicates the request should use the proxy. By default this is determined automatically based on the domain of the request url.
optionalcacheBust BooleanDefault Value:falseIndicates whether to send an extra query parameter to ensure the server doesn't supply cached values.
optionalallowImageDataAccess BooleanDefault Value:falseIndicates whether apps are allowed to read image data (when used with Canvas) from images hosted on third-party sites. Only applicable when
responseType = "image"
.optionalauthMode StringDefault Value:autoIndicates if and how requests to ArcGIS Services are authenticated. Only applicable when
esriConfig.request.useIdentity = true
.Known Value Description auto The user will be signed in when a secure resource is requested. anonymous An error will be returned when a secure resource is requested. immediate The user will be signed in before the resource is requested. no-prompt Checks for whether the user is already signed in. If so, no additional prompts display for sign-in.
Returns a promise that resolves to an object with the following specification. If the request returns an Error, the error object will include the details specified in EsriErrorDetails.
- Properties:
- optionaldata *
The requested data. Should match the
responseType
with the data return type. Possible types are: json, xml, text, blob, array-buffer, document, and image.optionalrequestOptions RequestOptionsThe options specified by the user in the data request. See RequestOptions for available properties.
optionalssl BooleanIf ssl is enabled or not.
optionalurls StringThe URL used to request the data.
optionalgetHeader() FunctionMethod for getting a header sent from the server.
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; });
API Reference search results
Name | Type | Module |
---|