Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractRestClient

Class to handle http(s) requests, build headers, collect data, report status codes, and header responses and passes control to session object for maintaining connection information (tokens, checking for timeout, etc...)

export
abstract

Hierarchy

Index

Constructors

constructor

Properties

Private lastByteReceived

lastByteReceived: number = 0

Last byte received when response is being streamed

memberof

AbstractRestClient

Private mBytesReceived

mBytesReceived: number = 0

Bytes received from the server response so far

memberof

AbstractRestClient

Private mChunks

mChunks: Buffer[] = []

Contains REST chucks

memberof

AbstractRestClient

Private mContentEncoding

mContentEncoding: ContentEncoding

If we get a response containing a Content-Encoding header, and it matches an encoding type that we recognize, it is saved here

memberof

AbstractRestClient

Private mContentLength

mContentLength: number

If we get a response containing a Content-Length header, it is saved here

memberof

AbstractRestClient

Private mData

mData: Buffer = Buffer.from([])

Contains buffered data after all REST chucks are received

memberof

AbstractRestClient

Private mDecode

mDecode: boolean = true

Whether or not to try and decode any encoded response

memberof

AbstractRestClient

Private mIsJson

mIsJson: boolean

Indicates if payload data is JSON to be stringified before writing

memberof

AbstractRestClient

Private mLogger

mLogger: Logger

Instance of logger

memberof

AbstractRestClient

Private mNormalizeRequestNewlines

mNormalizeRequestNewlines: boolean

Indicates if request data should have its newlines normalized to /n before sending each chunk to the server

memberof

AbstractRestClient

Private mNormalizeResponseNewlines

mNormalizeResponseNewlines: boolean

Indicates if response data should have its newlines normalized for the current platform (\r\n for windows, otherwise \n)

memberof

AbstractRestClient

Private mReject

Reject for errors when obtaining data

memberof

AbstractRestClient

Private mReqHeaders

mReqHeaders: any[]

Save req headers

memberof

AbstractRestClient

Private mRequest

mRequest: HTTP_VERB

Save request

memberof

AbstractRestClient

Private mRequestStream

mRequestStream: Readable

stream for outgoing request data to the server

memberof

AbstractRestClient

Private mResolve

Resolved when all data has been obtained

memberof

AbstractRestClient

Private mResource

mResource: string

Save resource

memberof

AbstractRestClient

Private mResponse

mResponse: any

Contain response from http(s) request

memberof

AbstractRestClient

Private mResponseStream

mResponseStream: Writable

Stream for incoming response data from the server. If specified, response data will not be buffered

memberof

AbstractRestClient

Private mSession

mSession: AbstractSession

representing connection to this api

Private mTask

Task used to display progress bars or other user feedback mechanisms Automatically updated if task is specified and streams are provided for upload/download

memberof

AbstractRestClient

Private mWriteData

mWriteData: any

Save write data

memberof

AbstractRestClient

Accessors

data

  • get data(): Buffer

dataString

  • get dataString(): string

log

requestFailure

  • get requestFailure(): boolean

requestSuccess

  • get requestSuccess(): boolean

response

  • get response(): any

session

Methods

Protected appendHeaders

  • appendHeaders(headers: any[] | undefined): any[]

Private appendInputHeaders

Private buildOptions

  • buildOptions(resource: string, request: string, reqHeaders?: any[]): IHTTPSOptions

Private onData

  • onData(respData: Buffer): void
  • Method to accumulate and buffer http request response data until our onEnd method is invoked, at which point all response data has been accounted for. NOTE(Kelosky): this method may be invoked multiple times.

    memberof

    AbstractRestClient

    Parameters

    • respData: Buffer

      any datatype and content

    Returns void

Private onEnd

  • onEnd(): void

Private populateError

  • Construct a throwable rest client error with all "relevant" diagnostic information. The caller should have the session, so not all input fields are present on the error response. Only the set required to understand "what may have gone wrong".

    The "exit" point for the implementation error override will also be called here. The implementation can choose to transform the IImperativeError details however they see fit.

    Parameters

    • error: IRestClientError

      The base request error. It is expected to already have msg, causeErrors, and the error source pre-populated.

    • Optional nodeClientError: any

    Returns RestClientError

    • The error that can be thrown or rejected.

Protected processError

  • Process and customize errors encountered in your client. This is called any time an error is thrown from a failed Rest request using this client. error before receiving any response body from the API. You can use this, for example, to set the error tag for you client or add additional details to the error message. If you return null or undefined, Imperative will use the default error generated for your failed request.

    memberof

    AbstractRestClient

    Parameters

    Returns IImperativeError

    processedError - the error with the fields set the way you want them

request

Private requestHandler

  • requestHandler(res: any): void

Private setTransferFlags

  • setTransferFlags(headers: OutgoingHttpHeaders): void

Generated using TypeDoc