ApiClient

ApiClient

new ApiClient()

Version:
  • 1.0

Classes

ApiClient

Members

(static, readonly) CollectionFormatEnum :String

Properties:
Name Type Description
CSV String

Comma-separated values. Value: csv

SSV String

Space-separated values. Value: ssv

TSV String

Tab-separated values. Value: tsv

PIPES String

Pipe(|)-separated values. Value: pipes

MULTI String

Native array. Value: multi

Enumeration of collection format separator strategies.

Type:
  • String

(static) instance :ApiClient

The default API client implementation.

Type:

Methods

paramToString(param) → {String}

Returns a string representation for an actual parameter.

Parameters:
Name Type Description
param

The actual parameter.

Returns:

The string representation of param.

Type
String

buildUrl(path, pathParams) → {String}

Builds full URL by appending the given path to the base URL and replacing path parameter place-holders with parameter values. NOTE: query parameters are not handled here.

Parameters:
Name Type Description
path String

The path to append to the base URL.

pathParams Object

The parameter values to append.

Returns:

The encoded path with parameter values substituted.

Type
String

isJsonMime(contentType) → {Boolean}

Checks whether the given content type represents JSON.
JSON content type examples:

  • application/json
  • application/json; charset=UTF8
  • APPLICATION/JSON
Parameters:
Name Type Description
contentType String

The MIME content type to check.

Returns:

true if contentType represents JSON, otherwise false.

Type
Boolean

jsonPreferredMime(contentTypes) → {String}

Chooses a content type from the given array, with JSON preferred; i.e. return JSON if included, otherwise return the first.

Parameters:
Name Type Description
contentTypes Array.<String>
Returns:

The chosen content type, preferring JSON.

Type
String

isFileParam(param) → {Boolean}

Checks whether the given parameter value represents file-like content.

Parameters:
Name Type Description
param

The parameter to check.

Returns:

true if param represents a file.

Type
Boolean

normalizeParams(params) → {Object.<String, Object>}

Normalizes parameter values:

  • remove nils
  • keep files and arrays
  • format to string with `paramToString` for other cases
Parameters:
Name Type Description
params Object.<String, Object>

The parameters as object properties.

Returns:

normalized parameters.

Type
Object.<String, Object>

buildCollectionParam(param, collectionFormat) → {String|Array}

Builds a string representation of an array-type actual parameter, according to the given collection format.

Parameters:
Name Type Description
param Array

An array parameter.

collectionFormat ApiClient.CollectionFormatEnum

The array element separator strategy.

Returns:

A string representation of the supplied collection, using the specified delimiter. Returns param as is if collectionFormat is multi.

Type
String | Array

applyAuthToRequest(request, authNames)

Applies authentication headers to the request.

Parameters:
Name Type Description
request Object

The request object created by a superagent() call.

authNames Array.<String>

An array of authentication method names.

deserialize(response, returnType)

Deserializes an HTTP response body into a value of the specified type.

Parameters:
Name Type Description
response Object

A SuperAgent response object.

returnType String | Array.<String> | Object.<String, Object> | function

The type to return. Pass a string for simple types or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type: all properties on data will be converted to this type.

Returns:

A value of the specified type.

callApi(path, httpMethod, pathParams, queryParams, collectionQueryParams, headerParams, formParams, bodyParam, authNames, contentTypes, accepts, returnType, callback) → {Object}

Invokes the REST service using the supplied settings and parameters.

Parameters:
Name Type Description
path String

The base URL to invoke.

httpMethod String

The HTTP method to use.

pathParams Object.<String, String>

A map of path parameters and their values.

queryParams Object.<String, Object>

A map of query parameters and their values.

collectionQueryParams Object.<String, Object>

A map of collection query parameters and their values.

headerParams Object.<String, Object>

A map of header parameters and their values.

formParams Object.<String, Object>

A map of form parameters and their values.

bodyParam Object

The value to pass as the request body.

authNames Array.<String>

An array of authentication type names.

contentTypes Array.<String>

An array of request MIME types.

accepts Array.<String>

An array of acceptable response MIME types.

returnType String | Array | ObjectFunction

The required type to return; can be a string for simple types or the constructor for a complex type.

callback ApiClient~callApiCallback

The callback function.

Returns:

The SuperAgent request object.

Type
Object

(static) parseDate(str) → {Date}

Parses a string representation of a date value.

Parameters:
Name Type Description
str String

The date value as an ISO-8601 full-date or date-time string.

Returns:

The parsed date object.

Type
Date

(static) convertToType(data, type)

Converts a value to the specified type.

Parameters:
Name Type Description
data String | Object

The data to convert, as a string or object.

type String | Array.<String> | Object.<String, Object> | function

The type to return. Pass a string for simple types or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type: all properties on data will be converted to this type.

Returns:

An instance of the specified type or null or undefined if data is null or undefined.

(static) constructFromObject(data, obj)

Constructs a new map or array model from REST data.

Parameters:
Name Type Description
data Object | Array

The REST data.

obj Object | Array

The target object or array.

Type Definitions

callApiCallback(error, data, response)

Callback function to receive the result of the operation.

Parameters:
Name Type Description
error String

Error message, if any.

data

The data returned by the service call.

response String

The complete HTTP response.