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 TypeSummaryFunction
Promise<RequestResponse>

Retrieves data from a remote server or uploads a file from a user's computer.

more details
more detailsrequest

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 String

The request URL.

optional

The options specified by the user in the data request. See RequestOptions for available properties.

Returns:
TypeDescription
Promise<RequestResponse>Returns a promise that resolves to an object with the RequestResponse specification. If the request returns an Error, the error object will include the details specified in EsriErrorDetails.

Type Definitions

EsriErrorDetails

The specification of the details object returned in an Error object.

Properties:
getHeader getHeader

A function to retrieve headers sent from the server.

httpStatus Number

The status of the http request.

messageCode String

The error message code.

messages String[]

Additional error message(s).

requestOptions Object

The query parameters sent with the http request.

Indicates if the request required https.

subCode Number

The error message subcode.

url String

The URL of the request that returned an error message.

getHeader(headerName){String}

A function to retrieve headers sent from the server.

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'));
  });
RequestOptions

An object with the following properties that describe the request.

Properties:
query Object
optional
Default Value:null

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

responseType String
optional
Default Value:json

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

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

optional

AbortSignal allows for cancelable requests. If canceled, the promise will be rejected with an error named AbortError. See also AbortController.

Example:

const controller = new AbortController();
const signal = controller.signal;

esriRequest(url, { signal })
  .then((response) => {
    // The request went OK
  })
  .catch((err) => {
    if (err.name === 'AbortError') {
      console.log('Request aborted');
    } else {
      console.error('Error encountered', err);
    }
  });

// Abort requests that are aware of the controller's signal
controller.abort();
headers Object
optional

Headers to use for the request. This is an object whose property names are header names. This option is ignored when responseType = "image".

timeout Number
optional
Default Value:60000

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

method String
optional
Default Value:auto

Indicates if the request should be made using the HTTP POST method. By default, this is determined automatically based on the request size.

Possible Values: auto | post

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
Default Value:false

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

cacheBust Boolean
optional
Default Value:false

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

authMode String
optional
Default Value:auto

Indicates if and how requests to ArcGIS Services are authenticated. Only applicable when esriConfig.request.useIdentity = true.

Known ValueDescription
autoThe user will be signed in when a secure resource is requested.
anonymousAn error will be returned when a secure resource is requested.
immediateThe user will be signed in before the resource is requested.
no-promptChecks for whether the user is already signed in. If so, no additional prompts display for sign-in.
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.

Properties:
data *
optional

The requested data. Should match the responseType with the data return type. Possible types are: json, xml, text, blob, array-buffer, document, and image.

requestOptions RequestOptions
optional

The options specified by the user in the data request. See RequestOptions for available properties.

optional

Indicates if the request required https.

url String
optional

The URL used to request the data.

getHeader getHeader
optional

Method 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

NameTypeModule
Loading...