Resource

external class Resource(options: ERROR CLASS: Symbol not found for JsAny)(source)

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.

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

Parameters

options

A url or an object describing initialization options

See also

Constructors

Link copied to clipboard
constructor(options: ERROR CLASS: Symbol not found for JsAny)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Initialization options for the Resource constructor

Link copied to clipboard
interface DeleteOptions
Link copied to clipboard
Link copied to clipboard
interface FetchOptions
Link copied to clipboard
Link copied to clipboard
interface HeadOptions
Link copied to clipboard
interface OptionsOptions
Link copied to clipboard
interface PatchOptions
Link copied to clipboard
interface PostOptions
Link copied to clipboard
interface PutOptions

Properties

Link copied to clipboard

The file extension of the resource.

Link copied to clipboard

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

Link copied to clipboard
var headers: ERROR CLASS: Symbol not found for JsAny

Additional HTTP headers that will be sent with the request.

Link copied to clipboard

True if the Resource refers to a blob URI.

Link copied to clipboard

True if the Resource refers to a cross origin URL.

Link copied to clipboard

True if the Resource refers to a data URI.

Link copied to clipboard

A proxy to be used when loading the resource.

Link copied to clipboard
val queryParameters: ERROR CLASS: Symbol not found for JsAny

Query parameters appended to the url.

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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.

Link copied to clipboard
val templateValues: ERROR CLASS: Symbol not found for JsAny

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

Link copied to clipboard
var url: String

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

Functions

Link copied to clipboard

Appends a forward slash to the URL.

Link copied to clipboard
fun appendQueryParameters(params: ERROR CLASS: Symbol not found for JsAny)

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.

Link copied to clipboard
fun clone(result: Resource? = definedExternally): Resource

Duplicates a Resource instance.

Link copied to clipboard
suspend fun delete(options: Resource.DeleteOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun deleteAsync(options: Resource.DeleteOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun fetch(options: Resource.FetchOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
suspend fun fetchArrayBuffer(): ERROR CLASS: Symbol not found for ArrayBuffer??

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.

Link copied to clipboard
fun fetchArrayBufferAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for ArrayBuffer>??
Link copied to clipboard
fun fetchAsync(options: Resource.FetchOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun fetchBlob(): ERROR CLASS: Symbol not found for Blob??

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.

Link copied to clipboard
fun fetchBlobAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for Blob>??
Link copied to clipboard
suspend fun fetchImage(options: Resource.FetchImageOptions? = definedExternally): ERROR CLASS: Symbol not found for CanvasImageSource??

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.

Link copied to clipboard
fun fetchImageAsync(options: Resource.FetchImageOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for CanvasImageSource>??
Link copied to clipboard
suspend fun fetchJson(): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun fetchJsonAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun fetchJsonp(callbackParameterName: String? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

Requests a resource using JSONP.

Link copied to clipboard
fun fetchJsonpAsync(callbackParameterName: String? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun fetchText(): String?

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.

Link copied to clipboard
fun fetchTextAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsString>??
Link copied to clipboard
suspend fun fetchXML(): ERROR CLASS: Symbol not found for XMLDocument??

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.

Link copied to clipboard
fun fetchXMLAsync(): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for XMLDocument>??
Link copied to clipboard
fun getBaseUri(includeQuery: Boolean? = definedExternally): String

Returns the base path of the Resource.

Link copied to clipboard

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

Link copied to clipboard
fun getUrlComponent(query: Boolean? = definedExternally, proxy: Boolean? = definedExternally): String

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

Link copied to clipboard
suspend fun head(options: Resource.HeadOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun headAsync(options: Resource.HeadOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun options(options: Resource.OptionsOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun optionsAsync(options: Resource.OptionsOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun patch(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PatchOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun patchAsync(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PatchOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun post(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PostOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun postAsync(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PostOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
suspend fun put(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PutOptions? = definedExternally): ERROR CLASS: Symbol not found for JsAny??

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.

Link copied to clipboard
fun putAsync(data: ERROR CLASS: Symbol not found for JsAny, options: Resource.PutOptions? = definedExternally): ERROR CLASS: Symbol not found for Promise<ERROR CLASS: Symbol not found for JsAny>??
Link copied to clipboard
fun setQueryParameters(params: ERROR CLASS: Symbol not found for JsAny, useAsDefault: Boolean? = definedExternally)

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.

Link copied to clipboard
fun setTemplateValues(template: ERROR CLASS: Symbol not found for JsAny, useAsDefault: Boolean? = definedExternally)

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.