require(["esri/request"], function(esriRequest) { /* code goes here */ });
Function: esri/request
Since: ArcGIS API for JavaScript 4.0

Retrieves data from a remote server or uploads a file.

See also:
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;
});

Method Overview

NameReturn TypeSummary
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 String

The request URL.

options Object
optional

An object with the following properties that describe the request.

Specification:
callbackParamName String
optional

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.

query Object
optional

If the request URL points to a web server that requires parameters, specify them here.

Default Value: null

responseType String
optional

Response format. When this value is image the method and timeout options are ignored.

Possible Values: json | xml | text | blob | array-buffer | document | image
Default Value: json

headers Object
optional

Headers to use for the request. This is an object whose property names are header names. This is not applicable for non-XHR requests.

timeout Number
optional

Indicates 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 when responseType = "image".

Default Value: 60000

method String
optional

Indicates 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: auto

optional

If 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.

useProxy Boolean
optional

Indicates the request should use the proxy. By default this is determined automatically based on the domain of the request url.

Default Value: false

cacheBust Boolean
optional

Indicates whether to send an extra query parameter to ensure the server doesn't supply cached values.

Default Value: false

allowImageDataAccess Boolean
optional

Indicates 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: false

Returns:
TypeDescription
PromiseReturns a promise that resolves to an object with the following specification.
PropertyTypeDescription
data*The requested data. See the table below to match the responseType with the data return type.
requestOptionsObjectThe options specified by the user in the data request. This has the same specification as the options object defined in the request parameters above.
urlStringThe URL used to request the data.
getHeader()getHeaderMethod for getting a header sent from the server.
The requested response types and their corresponding return types are described in the table below.

responseTypeReturn typeDescription
jsonObjectThe requested data object.
xmlXMLDocumentThe requested XML document.
textStringThe requested text.
blobBlobThe requested blob.
array-bufferArrayBufferThe requested ArrayBuffer.
documentHTMLDocumentThe requested HTML document.
imageHTMLImageElementThe 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 String

The name of the header.

Returns:
TypeDescription
StringThe 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'));
});

API Reference search results

NameTypeModule

There were no match results from your search criteria.