Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

Index

Constructors

constructor

Properties

Private mBytesReceived

mBytesReceived: number = 0

Bytes received from the server response so far

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 from REST chucks

memberof

AbstractRestClient

Private mDecode

mDecode: boolean

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 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[]

performRest

  • performRest(resource: string, request: HTTP_VERB, reqHeaders?: any[], writeData?: any, responseStream?: Writable, requestStream?: Readable, normalizeResponseNewLines?: boolean, normalizeRequestNewLines?: boolean, task?: ITaskWithStatus): Promise<string>
  • Perform the actual http REST call with appropriate user input

    deprecated
    • since version 4.4.9. Changed to wrapper for request(). Please use request() directly.
              It will be removed in version 5.0.0
      
    throws

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

    Parameters

    • resource: string

      URI for this request

    • request: HTTP_VERB

      REST request type GET|PUT|POST|DELETE

    • Optional reqHeaders: any[]

      option headers to include with request

    • Optional writeData: any

      data to write on this REST request

    • Optional responseStream: Writable

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

    • Optional requestStream: Readable

      stream for outgoing request data to the server

    • Optional normalizeResponseNewLines: boolean

      streaming only - true if you want newlines to be \r\n on windows when receiving data from the server to responseStream. Don't set this for binary responses

    • Optional normalizeRequestNewLines: boolean

      streaming only - true if you want \r\n to be replaced with \n when sending data to the server from requestStream. Don't set this for binary requests

    • Optional task: ITaskWithStatus

      task that will automatically be updated to report progress of upload or download to user

    Returns Promise<string>

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

Static deleteExpectBuffer

  • REST HTTP DELETE operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    Returns Promise<Buffer>

    • response body content from http(s) call

Static deleteExpectFullResponse

Static deleteExpectJSON

  • Wrap post for common error handling and supporting generic JSON types

    static
    throws

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

    memberof

    RestClient

    Type parameters

    • T: object

      object type to return

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      the API URI that we are targeting

    • Default value reqHeaders: any[] = []

      headers for the http(s) request

    Returns Promise<T>

    • object on promise

Static deleteExpectString

  • REST HTTP DELETE operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    Returns Promise<string>

    • response body content from http(s) call

Static deleteStreamed

  • REST HTTP DELETE operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • responseStream: Writable

      stream to which the response data will be written

    • Optional normalizeResponseNewLines: boolean

      streaming only - true if you want newlines to be \r\n on windows when receiving data from the server to responseStream. Don't set this for binary responses

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • empty string - data is not buffered for streamed requests

Static Private extractExpectedData

Static getExpectBuffer

  • REST HTTP GET operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    Returns Promise<Buffer>

    • response body content from http(s) call

Static getExpectFullResponse

Static getExpectJSON

  • Wrap get for common error handling and supporting generic JSON types

    static
    throws

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

    memberof

    RestClient

    Type parameters

    • T: object

      object type to return

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      the API URI that we are targeting

    • Default value reqHeaders: any[] = []

      headers for the http(s) request

    Returns Promise<T>

    • object on promise

Static getExpectString

  • REST HTTP GET operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    Returns Promise<string>

    • response body content from http(s) call

Static getStreamed

  • REST HTTP GET operation - streaming the response to a writable stream

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • responseStream: Writable

      the stream to which the response data will be written

    • Optional normalizeResponseNewLines: boolean

      streaming only - true if you want newlines to be \r\n on windows when receiving data from the server to responseStream. Don't set this for binary responses

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • empty string - data is not buffered for this request

Static hasQueryString

  • hasQueryString(query: string): boolean

Static postExpectBuffer

  • postExpectBuffer(session: AbstractSession, resource: string, reqHeaders?: any[], data?: any): Promise<Buffer>
  • REST HTTP POST operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • Optional data: any

      payload data

    Returns Promise<Buffer>

    • response body content from http(s) call

Static postExpectFullResponse

Static postExpectJSON

  • postExpectJSON<T>(session: AbstractSession, resource: string, reqHeaders?: any[], payload?: any): Promise<T>
  • Wrap post for common error handling and supporting generic JSON types

    static
    throws

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

    memberof

    RestClient

    Type parameters

    • T: object

      object type to return

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      the API URI that we are targeting

    • Default value reqHeaders: any[] = []

      headers for the http(s) request

    • Optional payload: any

      data to write on the http(s) request

    Returns Promise<T>

    • object on promise

Static postExpectString

  • postExpectString(session: AbstractSession, resource: string, reqHeaders?: any[], data?: any): Promise<string>
  • REST HTTP POST operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • Optional data: any

      payload data

    Returns Promise<string>

    • response body content from http(s) call

Static postStreamed

  • postStreamed(session: AbstractSession, resource: string, reqHeaders?: any[], responseStream: Writable, requestStream: Readable, normalizeResponseNewLines?: boolean, normalizeRequestNewLines?: boolean, task?: ITaskWithStatus): Promise<string>
  • REST HTTP POST operation streaming both the request and the response

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • responseStream: Writable

      stream to which the response data will be written

    • requestStream: Readable

      stream from which payload data will be read

    • Optional normalizeResponseNewLines: boolean

      streaming only - true if you want newlines to be \r\n on windows when receiving data from the server to responseStream. Don't set this for binary responses

    • Optional normalizeRequestNewLines: boolean

      streaming only - true if you want \r\n to be replaced with \n when sending data to the server from requestStream. Don't set this for binary requests

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • empty string - data is not buffered for this request

Static postStreamedRequestOnly

  • postStreamedRequestOnly(session: AbstractSession, resource: string, reqHeaders?: any[], requestStream: Readable, normalizeRequestNewLines?: boolean, task?: ITaskWithStatus): Promise<string>
  • REST HTTP POST operation, streaming only the request and not the response

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • requestStream: Readable

      stream from which payload data will be read

    • Optional normalizeRequestNewLines: boolean

      streaming only - true if you want \r\n to be replaced with \n when sending data to the server from requestStream. Don't set this for binary requests

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • string of the response

Static putExpectBuffer

  • REST HTTP PUT operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • data: any

      payload data

    Returns Promise<Buffer>

    • response body content from http(s) call

Static putExpectFullResponse

Static putExpectJSON

  • Wrap put for common error handling and supporting generic JSON types

    static
    throws

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

    memberof

    RestClient

    Type parameters

    • T: object

      object type to return

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      the API URI that we are targeting

    • Default value reqHeaders: any[] = []

      headers for the http(s) request

    • payload: any

      data to write on the http(s) request

    Returns Promise<T>

    • object on promise

Static putExpectString

  • REST HTTP PUT operation

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • data: any

      payload data

    Returns Promise<string>

    • response body content from http(s) call

Static putStreamed

  • putStreamed(session: AbstractSession, resource: string, reqHeaders?: any[], responseStream: Writable, requestStream: Readable, normalizeResponseNewLines?: boolean, normalizeRequestNewLines?: boolean, task?: ITaskWithStatus): Promise<string>
  • REST HTTP PUT operation with streamed response and request

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • responseStream: Writable

      stream to which the response data will be written

    • requestStream: Readable

      stream from which payload data will be read

    • Optional normalizeResponseNewLines: boolean

      streaming only - true if you want newlines to be \r\n on windows when receiving data from the server to responseStream. Don't set this for binary responses

    • Optional normalizeRequestNewLines: boolean

      streaming only - true if you want \r\n to be replaced with \n when sending data to the server from requestStream. Don't set this for binary requests

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • empty string - data is not buffered for streamed requests

Static putStreamedRequestOnly

  • putStreamedRequestOnly(session: AbstractSession, resource: string, reqHeaders?: any[], requestStream: Readable, normalizeRequestNewLines?: boolean, task?: ITaskWithStatus): Promise<string>
  • REST HTTP PUT operation with only streamed request, buffers response data and returns it

    static
    throws

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

    memberof

    RestClient

    Parameters

    • session: AbstractSession

      representing connection to this api

    • resource: string

      URI for which this request should go against

    • Default value reqHeaders: any[] = []

      headers to include in the REST request

    • requestStream: Readable

      stream from which payload data will be read

    • Optional normalizeRequestNewLines: boolean

      streaming only - true if you want \r\n to be replaced with \n when sending data to the server from requestStream. Don't set this for binary requests

    • Optional task: ITaskWithStatus

      task used to update the user on the progress of their request

    Returns Promise<string>

    • string of the response

Generated using TypeDoc