Class: BaseRequestHandler

BaseRequestHandler(clientObjopt)

Executes HTTP requests for SlashDB. Base class for DataDiscoveryResource and SQLPassThruQuery classes.

Constructor

new BaseRequestHandler(clientObjopt)

Create a BaseRequestHandler object for a given SlashDB instance

Parameters:
Name Type Attributes Default Description
clientObj SlashDBClient <optional>
null

a configured SlashDBClient object

Source:

Methods

_buildEndpointString(pathopt) → {string}

Builds the full endpoint to the requested resource. Meant for internal use only. Overloaded in DataDiscoveryResource/SQLPassThruQuery

Parameters:
Name Type Attributes Description
path string <optional>

an optional string containing a URI segment with SQL query parameters/values and URL query parameters
(e.g. /FirstName/Tim?distinct=true)

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 SQLPassThruFilter 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')

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')

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

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

Source:
Returns:

promise containing HTTP response status and data

Type
Promise

getHeaders()

Gets authentication common header for HTTP requests

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.

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.

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

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