Class: DataDiscoveryResource

DataDiscoveryResource(db, resource, clientObjopt)

Executes HTTP requests for SlashDB Data Discovery functionality. Extends the BaseRequestHandler class
for most methods.

Constructor

new DataDiscoveryResource(db, resource, clientObjopt)

Create a DataDiscoveryResource object for a given SlashDB instance

Parameters:
Name Type Attributes Description
db string | DataDiscoveryDatabase

name of database to interact with via this instance, or a previously configured DataDiscoveryDatabase object

resource string

name of resource (table) to interact with via this instance

clientObj SlashDBClient <optional>

an optional configured SlashDBClient object

Source:
Throws:
  • if db parameter is a DataDiscoveryObject that is missing dbName property or has invalid dbName property

    Type
    ReferenceError | TypeError
  • if db parameter is: not a DataDiscoveryObject/not a string/parses to a number

    Type
    TypeError
  • if resource parameter is not a string or an empty string, or parses to a number

    Type
    TypeError
  • if no clientObj parameter was given, and a valid SlashDBClient object is not contained within db parameter,
    which must be a DataDiscoveryDatabase object if clientObj is omitted

    Type
    ReferenceError

Extends

Methods

_buildEndpointString(pathopt) → {string}

Builds the full endpoint to the requested resource. Meant for internal use only.

Parameters:
Name Type Attributes Description
path string | DataDiscoveryFilter <optional>

an optional string containing a URI segment with SQL query parameters/values and URL query parameters
(e.g. /FirstName/Tim?distinct=true), or a DataDiscoveryFilter object that contains all the query details

Overrides:
Source:
Throws:
  • if no SlashDBClient object is found attached to this object

    Type
    ReferenceError
  • if path parameter is an empty string

    Type
    SyntaxError
  • if path parameter is neither a string or a DataDiscoveryFilter object

    Type
    TypeError
Returns:

the full endpoint

Type
string

accept(format) → {BaseRequestHandler}

Sets Accept header value for HTTP requests

Parameters:
Name Type Description
format string

a valid MIME type (e.g. 'application/json'), or a key value of the validMimeTypes property in this class (e.g. 'json','csv')

Overrides:
Source:
Throws:
  • if format missing

    Type
    TypeError
  • if format is not string

    Type
    TypeError
Returns:

this object

Type
BaseRequestHandler

contentType(format) → {BaseRequestHandler}

Sets Content-Type header value for HTTP POST/PUT requests

Parameters:
Name Type Description
format string

a valid MIME type (e.g. 'application/json'), or a key value of the validMimeTypes property in this class (e.g. 'json','csv')

Overrides:
Source:
Throws:
  • if format missing

    Type
    TypeError
  • if format is not string

    Type
    TypeError
Returns:

this object

Type
BaseRequestHandler

(async) delete(pathopt) → {Promise}

Executes HTTP DELETE request

Parameters:
Name Type Attributes Description
path string | DataDiscoveryFilter | SQLPassThruFilter <optional>

an optional string containing a URI segment with URL query parameters
(e.g. /Customer/FirstName/Tim?distinct=true), or a DataDiscoveryFilter/SQLPassThruFilter object that contains all the query details

Overrides:
Source:
Returns:

promise containing HTTP response status and data

Type
Promise

(async) get(pathopt) → {Promise}

Executes HTTP GET request

Parameters:
Name Type Attributes Description
path string | DataDiscoveryFilter | SQLPassThruFilter <optional>

an optional string containing a URI segment with URL query parameters
(e.g. /Customer/FirstName/Tim?distinct=true), or a DataDiscoveryFilter/SQLPassThruFilter object that contains all the query details

Overrides:
Source:
Returns:

promise containing HTTP response status and data

Type
Promise

getHeaders()

Gets authentication common header for HTTP requests

Overrides:
Source:

(async) post(data, pathopt) → {Promise}

Executes HTTP POST request

Parameters:
Name Type Attributes Description
data string | object

an object or string containing data values to include in the POST request body. Can be JSON, an object, or CSV/XML formatted string

path string | DataDiscoveryFilter | SQLPassThruFilter <optional>

an optional string containing a URI segment with URL query parameters
(e.g. /Customer/FirstName/Tim?distinct=true), or a DataDiscoveryFilter/SQLPassThruFilter object that contains all the query details. Not used under normal
circumstances.

Overrides:
Source:
Returns:

promise containing HTTP response status and data

Type
Promise

(async) put(data, path) → {Promise}

Executes HTTP PUT request

Parameters:
Name Type Description
data string | object

an object or string containing data values to include in the PUT request body. Can be JSON, an object, or CSV/XML formatted string

path string | DataDiscoveryFilter | SQLPassThruFilter | null | undefined

a string containing a URI segment with URL query parameters
(e.g. /Customer/FirstName/Tim?distinct=true), or a DataDiscoveryFilter/SQLPassThruFilter object that contains all the query details. Set to null or undefined
if not required.

Overrides:
Source:
Returns:

promise containing HTTP response status and data

Type
Promise

setExtraHeaders(headersObj) → {BaseRequestHandler}

Sets arbitrary custom header value for HTTP requests

Parameters:
Name Type Description
headersObj object

an object containing key/value pairs of header properties

Overrides:
Source:
Throws:
  • headersObj is not an object

    Type
    TypeError
  • if the value of a key/value pair is not a string or number

    Type
    TypeError
Returns:

this object

Type
BaseRequestHandler