Class: BaseUrlAdapter

undercomplicate.BaseUrlAdapter()

Fetch data over the web, usually from a REST API that returns JSON

Constructor

new BaseUrlAdapter()

Parameters:
Name Type Description
config.url string

The URL to request

Source:

Extends

Methods

_annotateRecords(records, options) → {*}

Perform custom client-side operations on the retrieved data. For example, add calculated fields or perform rapid client-side filtering on cached data. Annotations are applied after cache, which means that the same network request can be dynamically annotated/filtered in different ways in response to user interactions.

This result is currently not cached, but it may become so in the future as responsibility for dynamic UI behavior moves to other layers of the application.

Parameters:
Name Type Description
records Array.<Object>
options Object
Overrides:
Source:
Returns:
Type
*

_buildRequestOptions(options, dependent_data) → {*}

Build an object with options that control the request. This can take into account both explicit options, and prior data.

Parameters:
Name Type Description
options Object

Any global options passed in via getData. Eg, in locuszoom, every request is passed a copy of plot.state as the options object, in which case every adapter would expect certain basic information like chr, start, end to be available.

dependent_data Array.<Object>

If the source is called with dependencies, this function will receive one argument with the fully parsed response data from each other source it depends on. Eg, ld(assoc) means that the LD adapter would be called with the data from an association request as a function argument. Each dependency is its own argument: there can be 0, 1, 2, ...N arguments.

Overrides:
Source:
Returns:

An options object containing initial options, plus any calculated values relevant to the request.

Type
*

_getCacheKey()

Default cache key is the URL for this request

Overrides:
Source:

_normalizeResponse(response_text, options) → {*}

Convert the response format into a list of objects, one per datapoint. Eg split lines of a text file, or parse a blob of json.

Parameters:
Name Type Description
response_text *

The raw response from performRequest, be it text, binary, etc. For most web based APIs, it is assumed to be text, and often JSON.

options Object

Request options. These are not typically used when normalizing a response, but the object is available.

Overrides:
Source:
Returns:

A list of objects, each object representing one row of data {column_name: value_for_row}

Type
*

_performRequest(options) → {Promise}

Perform the act of data retrieval (eg from a URL, blob, or JSON entity)

Parameters:
Name Type Description
options object

Request options from _buildRequestOptions

Overrides:
Source:
Returns:
Type
Promise

_postProcessResponse(records, options)

A hook to transform the response after all operations are done. For example, this can be used to prefix fields with a namespace unique to the request, like log_pvalue -> assoc:log_pvalue. (by applying namespace prefixes to field names last, annotations and validation can happen on the actual API payload, without having to guess what the fields were renamed to).

Parameters:
Name Type Description
records
options
Overrides:
Source:

getData(options, …dependent_data) → {Promise.<*>}

All adapters must implement this method to asynchronously return data. All other methods are simply internal hooks to customize the actual request for data.

Parameters:
Name Type Attributes Description
options object

Shared options for this request. In LocusZoom, this is typically a copy of plot.state.

dependent_data Array.<Array> <repeatable>

Zero or more recordsets corresponding to each individual adapter that this one depends on. Can be used to build a request that takes into account prior data.

Overrides:
Source:
Returns:
Type
Promise.<*>