# Resource

#### new Cesium.Resource(options)
engine/Source/Core/Resource.js 93

A resource that includes the location and any other parameters we need to retrieve it or create derived resources. It also provides the ability to retry requests.

Name | Type | Description
--- | --- | ---
`options` | string | Resource.ConstructorOptions | A url or an object describing initialization options

##### Example:

    function refreshTokenRetryCallback(resource, error) {
      if (error.statusCode === 403) {
        // 403 status code means a new token should be generated
        return getNewAccessToken()
          .then(function(token) {
            resource.queryParameters.access_token = token;
            return true;
          })
          .catch(function() {
            return false;
          });
      }

      return false;
    }

    const resource = new Resource({
       url: 'http://server.com/path/to/resource.json',
       proxy: new DefaultProxy('/proxy/'),
       headers: {
         'X-My-Header': 'valueOfHeader'
       },
       queryParameters: {
         'access_token': '123-435-456-000'
       },
       retryCallback: refreshTokenRetryCallback,
       retryAttempts: 1
    });

### Members

#### static constant Cesium.Resource.DEFAULT : Resource
engine/Source/Core/Resource.js 2263

A resource instance initialized to the current browser location

#### static readonly Cesium.Resource.isBlobSupported : boolean
engine/Source/Core/Resource.js 267

Returns true if blobs are supported.

#### readonly extension : string
engine/Source/Core/Resource.js 326

The file extension of the resource.

#### hasHeaders : boolean
engine/Source/Core/Resource.js 374

True if the Resource has request headers. This is equivalent to checking if the headers property has any keys.

#### headers : object
engine/Source/Core/Resource.js 114

Additional HTTP headers that will be sent with the request.

#### isBlobUri : boolean
engine/Source/Core/Resource.js 350

True if the Resource refers to a blob URI.

#### isCrossOriginUrl : boolean
engine/Source/Core/Resource.js 362

True if the Resource refers to a cross origin URL.

#### isDataUri : boolean
engine/Source/Core/Resource.js 338

True if the Resource refers to a data URI.

#### proxy : Proxy
engine/Source/Core/Resource.js 128

A proxy to be used when loading the resource.

#### readonly queryParameters : object
engine/Source/Core/Resource.js 283

Query parameters appended to the url.

#### request : Request
engine/Source/Core/Resource.js 121

A Request object that will be used. Intended for internal use only.

#### retryAttempts : number
engine/Source/Core/Resource.js 142

The number of times the retryCallback should be called before giving up.

#### retryCallback : function
engine/Source/Core/Resource.js 135

Function to call when a request for this resource fails. If it returns true or a Promise that resolves to true, the request will be retried.

#### readonly templateValues : object
engine/Source/Core/Resource.js 297

The key/value pairs used to replace template parameters in the url.

#### url : string
engine/Source/Core/Resource.js 309

The url to the resource with template values replaced, query string appended and encoded by proxy if one was set.

### Methods

#### static Cesium.Resource.delete(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1598

Creates a Resource from a URL and calls delete() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`data` | object |  | optional Data that is posted with the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetch(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1541

Creates a Resource from a URL and calls fetch() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchArrayBuffer(options) → Promise.<ArrayBuffer>|undefined
engine/Source/Core/Resource.js 823

Creates a Resource and calls fetchArrayBuffer() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchBlob(options) → Promise.<Blob>|undefined
engine/Source/Core/Resource.js 867

Creates a Resource and calls fetchBlob() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchImage(options) → Promise.<(ImageBitmap|HTMLImageElement)>|undefined
engine/Source/Core/Resource.js 1080

Creates a Resource and calls fetchImage() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`flipY` | boolean | `false` | optional Whether to vertically flip the image during fetch and decode. Only applies when requesting an image and the browser supports `createImageBitmap`.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`preferBlob` | boolean | `false` | optional If true, we will load the image via a blob.
`preferImageBitmap` | boolean | `false` | optional If true, image will be decoded during fetch and an `ImageBitmap` is returned.
`skipColorSpaceConversion` | boolean | `false` | optional If true, any custom gamma or color profiles in the image will be ignored. Only applies when requesting an image and the browser supports `createImageBitmap`.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchJson(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1197

Creates a Resource and calls fetchJson() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchJsonp(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1349

Creates a Resource from a URL and calls fetchJsonp() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`callbackParameterName` | string | `'callback'` | optional The callback parameter name that the server expects.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchText(options) → Promise.<string>|undefined
engine/Source/Core/Resource.js 1136

Creates a Resource and calls fetchText() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.fetchXML(options) → Promise.<XMLDocument>|undefined
engine/Source/Core/Resource.js 1246

Creates a Resource and calls fetchXML() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.head(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1655

Creates a Resource from a URL and calls head() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.options(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1711

Creates a Resource from a URL and calls options() on it.

Name | Type | Description
--- | --- | ---
`options` | string | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.patch(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1895

Creates a Resource from a URL and calls patch() on it.

Name | Type | Description
--- | --- | ---
`options` | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`data` | object |  | Data that is posted with the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.post(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1773

Creates a Resource from a URL and calls post() on it.

Name | Type | Description
--- | --- | ---
`options` | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`data` | object |  | Data that is posted with the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### static Cesium.Resource.put(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1834

Creates a Resource from a URL and calls put() on it.

Name | Type | Description
--- | --- | ---
`options` | object | A url or an object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | The url of the resource.
`data` | object |  | Data that is posted with the resource.
`queryParameters` | object |  | optional An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | `0` | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`responseType` | string |  | optional The type of response. This controls the type of item returned.
`overrideMimeType` | string |  | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

#### appendForwardSlash()
engine/Source/Core/Resource.js 780

Appends a forward slash to the URL.

#### appendQueryParameters(params)
engine/Source/Core/Resource.js 625

Combines the specified object and the existing query parameters. This allows you to add many parameters at once, as opposed to adding them one at a time to the queryParameters property.

Name | Type | Description
--- | --- | ---
`params` | object | The query parameters

#### clone(result) → Resource
engine/Source/Core/Resource.js 737

Duplicates a Resource instance.

Name | Type | Description
--- | --- | ---
`result` | Resource | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Resource instance if one was not provided.

#### delete(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1574

Asynchronously deletes the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.delete()
      .then(function(body) {
          // use the data
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetch(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1518

Asynchronously loads the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled. It's recommended that you use the more specific functions eg. fetchJson, fetchBlob, etc.

Name | Type | Description
--- | --- | ---
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.fetch()
      .then(function(body) {
          // use the data
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchArrayBuffer() → Promise.<ArrayBuffer>|undefined
engine/Source/Core/Resource.js 803

Asynchronously loads the resource as raw binary data. Returns a promise that will resolve to an ArrayBuffer once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load a single URL asynchronously
    resource.fetchArrayBuffer().then(function(arrayBuffer) {
        // use the data
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchBlob() → Promise.<Blob>|undefined
engine/Source/Core/Resource.js 847

Asynchronously loads the given resource as a blob. Returns a promise that will resolve to a Blob once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load a single URL asynchronously
    resource.fetchBlob().then(function(blob) {
        // use the data
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchImage(options) → Promise.<(ImageBitmap|HTMLImageElement)>|undefined
engine/Source/Core/Resource.js 901

Asynchronously loads the given image resource. Returns a promise that will resolve to an ImageBitmap if `preferImageBitmap` is true and the browser supports `createImageBitmap` or otherwise an Image once loaded, or reject if the image failed to load.

Name | Type | Description
--- | --- | ---
`options` | object | optional An object with the following properties.
Name | Type | Default | Description
--- | --- | --- | ---
`preferBlob` | boolean | `false` | optional If true, we will load the image via a blob.
`preferImageBitmap` | boolean | `false` | optional If true, image will be decoded during fetch and an `ImageBitmap` is returned.
`flipY` | boolean | `false` | optional If true, image will be vertically flipped during decode. Only applies if the browser supports `createImageBitmap`.
`skipColorSpaceConversion` | boolean | `false` | optional If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports `createImageBitmap`.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load a single image asynchronously
    resource.fetchImage().then(function(image) {
        // use the loaded image
    }).catch(function(error) {
        // an error occurred
    });

    // load several images in parallel
    Promise.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {
        // images is an array containing all the loaded images
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchJson() → Promise.<any>|undefined
engine/Source/Core/Resource.js 1163

Asynchronously loads the given resource as JSON. Returns a promise that will resolve to a JSON object once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not already specified.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.fetchJson().then(function(jsonData) {
        // Do something with the JSON object
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchJsonp(callbackParameterName) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1268

Requests a resource using JSONP.

Name | Type | Default | Description
--- | --- | --- | ---
`callbackParameterName` | string | `'callback'` | optional The callback parameter name that the server expects.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load a data asynchronously
    resource.fetchJsonp().then(function(data) {
        // use the loaded data
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- CommonJS Promises/A

#### fetchText() → Promise.<string>|undefined
engine/Source/Core/Resource.js 1116

Asynchronously loads the given resource as text. Returns a promise that will resolve to a String once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load text from a URL, setting a custom header
    const resource = new Resource({
      url: 'http://someUrl.com/someJson.txt',
      headers: {
        'X-Custom-Header' : 'some value'
      }
    });
    resource.fetchText().then(function(text) {
        // Do something with the text
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- XMLHttpRequest
- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchXML() → Promise.<XMLDocument>|undefined
engine/Source/Core/Resource.js 1225

Asynchronously loads the given resource as XML. Returns a promise that will resolve to an XML Document once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    // load XML from a URL, setting a custom header
    Cesium.loadXML('http://someUrl.com/someXML.xml', {
      'X-Custom-Header' : 'some value'
    }).then(function(document) {
        // Do something with the document
    }).catch(function(error) {
        // an error occurred
    });

##### See:

- XMLHttpRequest
- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### getBaseUri(includeQuery) → string
engine/Source/Core/Resource.js 773

Returns the base path of the Resource.

Name | Type | Default | Description
--- | --- | --- | ---
`includeQuery` | boolean | `false` | optional Whether or not to include the query string and fragment form the uri

##### Returns:

The base URI of the resource

#### getDerivedResource(options) → Resource
engine/Source/Core/Resource.js 664

Returns a resource relative to the current instance. All properties remain the same as the current instance unless overridden in options.

Name | Type | Description
--- | --- | ---
`options` | object | An object with the following properties
Name | Type | Default | Description
--- | --- | --- | ---
`url` | string |  | optional The url that will be resolved relative to the url of the current instance.
`queryParameters` | object |  | optional An object containing query parameters that will be combined with those of the current instance.
`templateValues` | object |  | optional Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance.
`headers` | object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The function to call when loading the resource fails.
`retryAttempts` | number |  | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`preserveQueryParameters` | boolean | `false` | optional If true, this will keep all query parameters from the current resource and derived resource. If false, derived parameters will replace those of the current resource.

##### Returns:

The resource derived from the current one.

#### getUrlComponent(query, proxy) → string
engine/Source/Core/Resource.js 541

Returns the url, optional with the query string and processed by a proxy.

Name | Type | Default | Description
--- | --- | --- | ---
`query` | boolean | `false` | optional If true, the query string is included.
`proxy` | boolean | `false` | optional If true, the url is processed by the proxy object, if defined.

##### Returns:

The url with all the requested components.

#### head(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1632

Asynchronously gets headers the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.head()
      .then(function(headers) {
          // use the data
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### options(options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1688

Asynchronously gets options the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.options()
      .then(function(headers) {
          // use the data
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### patch(data, options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1868

Asynchronously patches data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | object | Data that is posted with the resource.
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.patch(data)
      .then(function(result) {
          // use the result
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### post(data, options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1746

Asynchronously posts data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | object | Data that is posted with the resource.
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`data` | object | optional Data that is posted with the resource.
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.post(data)
      .then(function(result) {
          // use the result
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### put(data, options) → Promise.<any>|undefined
engine/Source/Core/Resource.js 1807

Asynchronously puts data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | object | Data that is posted with the resource.
`options` | object | optional Object with the following properties:
Name | Type | Description
--- | --- | ---
`responseType` | string | optional The type of response. This controls the type of item returned.
`headers` | object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | string | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

##### Example:

    resource.put(data)
      .then(function(result) {
          // use the result
      }).catch(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### setQueryParameters(params, useAsDefault)
engine/Source/Core/Resource.js 603

Combines the specified object and the existing query parameters. This allows you to add many parameters at once, as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.

Name | Type | Default | Description
--- | --- | --- | ---
`params` | object |  | The query parameters
`useAsDefault` | boolean | `false` | optional If true the params will be used as the default values, so they will only be set if they are undefined.

#### setTemplateValues(template, useAsDefault)
engine/Source/Core/Resource.js 640

Combines the specified object and the existing template values. This allows you to add many values at once, as opposed to adding them one at a time to the templateValues property. If a value is already set, it will become an array and the new value will be appended.

Name | Type | Default | Description
--- | --- | --- | ---
`template` | object |  | The template values
`useAsDefault` | boolean | `false` | optional If true the values will be used as the default values, so they will only be set if they are undefined.

#### toString() → string
engine/Source/Core/Resource.js 397

Override Object#toString so that implicit string conversion gives the complete URL represented by this Resource.

##### Returns:

The URL represented by this Resource

### Type Definitions

#### Cesium.Resource.ConstructorOptions
engine/Source/Core/Resource.js 39

Initialization options for the Resource constructor

##### Properties:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`url` | string |  |  | The url of the resource.
`queryParameters` | object | <optional> |  | An object containing query parameters that will be sent when retrieving the resource.
`templateValues` | object | <optional> |  | Key/Value pairs that are used to replace template values (eg. {x}).
`headers` | object | <optional> | {} | Additional HTTP headers that will be sent.
`proxy` | Proxy | <optional> |  | A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback | <optional> |  | The Function to call when a request for this resource fails. If it returns true, the request will be retried.
`retryAttempts` | number | <optional> | 0 | The number of times the retryCallback should be called before giving up.
`request` | Request | <optional> |  | A Request object that will be used. Intended for internal use only.
`parseUrl` | boolean | <optional> | true | If true, parse the url for query parameters; otherwise store the url without change

#### Cesium.Resource.RetryCallback(resource, error) → boolean|Promise.<boolean>
engine/Source/Core/Resource.js 2272

A function that returns the value of the property.

Name | Type | Description
--- | --- | ---
`resource` | Resource | optional The resource that failed to load.
`error` | RequestErrorEvent | optional The error that occurred during the loading of the resource.

##### Returns:

If true or a promise that resolved to true, the resource will be retried. Otherwise the failure will be returned.

Need help? The fastest way to get answers is from the community and team on the Cesium Forum.