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

- AbstractRestClient
  - RestClient

## Index

### Constructors

- constructor

### Properties

- lastByteReceived
- lastByteReceivedUpload
- mBytesReceived
- mChunks
- mContentEncoding
- mContentLength
- mData
- mDecode
- mIsJson
- mLogger
- mNormalizeRequestNewlines
- mNormalizeResponseNewlines
- mReject
- mReqHeaders
- mRequest
- mRequestStream
- mResolve
- mResource
- mResponse
- mResponseStream
- mSession
- mTask
- mWriteData

### Accessors

- data
- dataString
- log
- requestFailure
- requestSuccess
- response
- session

### Methods

- appendHeaders
- appendInputHeaders
- buildOptions
- onData
- onEnd
- populateError
- processError
- request
- requestHandler
- setBearerAuth
- setCertPemAuth
- setPasswordAuth
- setTokenAuth
- setTransferFlags
- validateRestHostname

## Constructors

### constructor

- new AbstractRestClient(mSession: AbstractSession, topDefaultAuth?: typeof AUTH_TYPE_BASIC | typeof AUTH_TYPE_TOKEN): AbstractRestClient

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:233

  Creates an instance of AbstractRestClient.

  memberof

    AbstractRestClient

  #### Parameters

  - ##### mSession: AbstractSession

    representing connection to this api

  - ##### Default value topDefaultAuth: typeof AUTH_TYPE_BASIC | typeof AUTH_TYPE_TOKEN = SessConstants.AUTH_TYPE_TOKEN

         The type of authentication used as the top selection in a default
         authentication order (when the user has not specified authOrder).
         The default value of AUTH_TYPE_TOKEN maintains backward compatibility
         with previous releases.

  #### Returns AbstractRestClient

## Properties

### Private lastByteReceived

lastByteReceived: number = 0

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:225

Last byte received when response is being streamed

memberof

  AbstractRestClient

### Private lastByteReceivedUpload

lastByteReceivedUpload: number = 0

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:233

Last byte received when upload is being streamed

memberof

  AbstractRestClient

### Private mBytesReceived

mBytesReceived: number = 0

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:209

Bytes received from the server response so far

memberof

  AbstractRestClient

### Private mChunks

mChunks: Buffer[] = []

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:58

Contains REST chucks

memberof

  AbstractRestClient

### Private mContentEncoding

mContentEncoding: ContentEncoding

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:117

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

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:107

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

memberof

  AbstractRestClient

### Private mData

mData: Buffer = Buffer.from([])

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:66

Contains buffered data after all REST chucks are received

memberof

  AbstractRestClient

### Private mDecode

mDecode: boolean = true

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:217

Whether or not to try and decode any encoded response

memberof

  AbstractRestClient

### Private mIsJson

mIsJson: boolean

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:125

Indicates if payload data is JSON to be stringified before writing

memberof

  AbstractRestClient

### Private mLogger

mLogger: Logger

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:74

Instance of logger

memberof

  AbstractRestClient

### Private mNormalizeRequestNewlines

mNormalizeRequestNewlines: boolean

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:134

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

memberof

  AbstractRestClient

### Private mNormalizeResponseNewlines

mNormalizeResponseNewlines: boolean

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:143

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

memberof

  AbstractRestClient

### Private mReject

mReject: ImperativeReject

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:90

Reject for errors when obtaining data

memberof

  AbstractRestClient

### Private mReqHeaders

mReqHeaders: any[]

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:167

Save req headers

memberof

  AbstractRestClient

### Private mRequest

mRequest: HTTP_VERB

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:159

Save request

memberof

  AbstractRestClient

### Private mRequestStream

mRequestStream: Readable

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:192

stream for outgoing request data to the server

memberof

  AbstractRestClient

### Private mResolve

mResolve: RestClientResolve

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:82

Resolved when all data has been obtained

memberof

  AbstractRestClient

### Private mResource

mResource: string

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:151

Save resource

memberof

  AbstractRestClient

### Private mResponse

mResponse: any

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:98

Contain response from http(s) request

memberof

  AbstractRestClient

### Private mResponseStream

mResponseStream: Writable

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:184

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

memberof

  AbstractRestClient

### Private Readonly mSession

mSession: AbstractSession

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:246

representing connection to this api

### Private mTask

mTask: ITaskWithStatus

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:201

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

- Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:175

Save write data

memberof

  AbstractRestClient

## Accessors

### data

- get data(): Buffer

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1116

  Return http(s) response body as a buffer

  readonly
  memberof

    AbstractRestClient

  #### Returns Buffer

### dataString

- get dataString(): string

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1126

  Return http(s) response body as a string

  readonly
  memberof

    AbstractRestClient

  #### Returns string

### log

- get log(): Logger

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1159

  Return the logger object for ease of reference

  readonly
  memberof

    AbstractRestClient

  #### Returns Logger

### requestFailure

- get requestFailure(): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1106

  Return whether or not a REST request was successful by HTTP status code

  readonly
  memberof

    AbstractRestClient

  #### Returns boolean

### requestSuccess

- get requestSuccess(): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1091

  Return whether or not a REST request was successful by HTTP status code

  readonly
  memberof

    AbstractRestClient

  #### Returns boolean

### response

- get response(): any

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1139

  Return http(s) response object

  readonly
  memberof

    AbstractRestClient

  #### Returns any

### session

- get session(): Session

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1149

  Return this session object

  readonly
  memberof

    AbstractRestClient

  #### Returns Session

## Methods

### Protected appendHeaders

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

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:477

  Append specific headers for all requests by overriding this implementation

  memberof

    AbstractRestClient

  #### Parameters

  - ##### headers: any[] | undefined

    list of headers

  #### Returns any[]

  - completed list of headers

### Private appendInputHeaders

- appendInputHeaders(options: IHTTPSOptions, reqHeaders?: any[]): IHTTPSOptions

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1038

  Appends output headers to the http(s) request

  memberof

    AbstractRestClient

  #### Parameters

  - ##### options: IHTTPSOptions

    partially populated options objects

  - ##### Optional reqHeaders: any[]

  #### Returns IHTTPSOptions

  - with populated headers

### Private buildOptions

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

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:514

  Build http(s) options based upon session settings and request.

  throws

    {ImperativeError} - if the hostname is invalid or credentials are not passed to a session that requires auth

  memberof

    AbstractRestClient

  #### Parameters

  - ##### resource: string

    URI for this request

  - ##### request: string

    REST request type GET|PUT|POST|DELETE

  - ##### Optional reqHeaders: any[]

    option headers to include with request

  #### Returns IHTTPSOptions

  - completed options object

### Private onData

- onData(respData: Buffer): void

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:849

  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

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:892

  Method that must be implemented to extend the IRestClient class. This is the client specific implementation for what action to perform after all response data has been collected.

  memberof

    AbstractRestClient

  #### Returns void

### Private populateError

- populateError(error: IRestClientError, nodeClientError?: any): RestClientError

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:949

  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

- processError(_error: IImperativeError): IImperativeError

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:498

  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

  - ##### _error: IImperativeError

  #### Returns IImperativeError

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

### request

- request(options: IRestOptions): Promise<string>

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:287

  Perform the actual http REST call with appropriate user input

  throws

    if the request gets a status code outside of the 200 range or other connection problems occur (e.g. connection refused)

  memberof

    AbstractRestClient

  #### Parameters

  - ##### options: IRestOptions

  #### Returns Promise<string>

### Private requestHandler

- requestHandler(res: any): void

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:775

  Callback from http(s).request

  memberof

    AbstractRestClient

  #### Parameters

  - ##### res: any

    https response

  #### Returns void

### Private setBearerAuth

- setBearerAuth(restOptionsToSet: any): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:725

  Set bearer auth token into our REST request authentication options.

  memberof

    AbstractRestClient

  #### Parameters

  - ##### restOptionsToSet: any

         The set of REST request options into which the credentials will be set.

  #### Returns boolean

  True if this function sets authentication options. False otherwise.

### Private setCertPemAuth

- setCertPemAuth(restOptionsToSet: any): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:751

  Set a PEM certificate auth into our REST request authentication options.

  memberof

    AbstractRestClient

  #### Parameters

  - ##### restOptionsToSet: any

         The set of REST request options into which the credentials will be set.

  #### Returns boolean

  True if this function sets authentication options. False otherwise.

### Private setPasswordAuth

- setPasswordAuth(restOptionsToSet: any): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:690

  Set user and password auth (A.K.A basic authentication) into our REST request authentication options if user and password values are specified in the session supplied to this class.

  memberof

    AbstractRestClient

  #### Parameters

  - ##### restOptionsToSet: any

         The set of REST request options into which the credentials will be set.

  #### Returns boolean

  True if this function sets authentication options. False otherwise.

### Private setTokenAuth

- setTokenAuth(restOptionsToSet: any): boolean

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:661

  Set token auth into our REST request authentication options if a token value is specified in the session supplied to this class.

  memberof

    AbstractRestClient

  #### Parameters

  - ##### restOptionsToSet: any

         The set of REST request options into which the credentials will be set.

  #### Returns boolean

  True if this function sets authentication options. False otherwise.

### Private setTransferFlags

- setTransferFlags(headers: OutgoingHttpHeaders): void

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1058

  Determine whether we should stringify or leave writable data alone

  memberof

    AbstractRestClient

  #### Parameters

  - ##### headers: OutgoingHttpHeaders

    options containing populated headers

  #### Returns void

### Private validateRestHostname

- validateRestHostname(hostname: string): void

- - Defined in @zowe/imperative/src/rest/src/client/AbstractRestClient.ts:1077

  Determine if the hostname parameter is valid before attempting the request

  memberof

    AbstractRestClient

  throws

    {ImperativeError} - if the hostname is invalid

  #### Parameters

  - ##### hostname: string

    the hostname to check

  #### Returns void

Generated using TypeDoc