Options
All
  • Public
  • Public/Protected
  • All
Menu

HTTP Client for REST requests. Send and receive JSON data. Sign request with AWS credentials if available Usage:

const restClient = new RestClient();
restClient.get('...')
.then(function(data) {
console.log(data);
})
.catch(err => console.log(err));

Hierarchy

  • RestClient

Index

Constructors

constructor

Properties

Credentials

Credentials: CredentialsClass = Credentials

Methods

ajax

  • ajax(urlOrApiInfo: string | ApiInfo, method: string, init: any): any
  • Basic HTTP request. Customizable

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • method: string

      Request HTTP method

    • init: any

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

cancel

  • cancel(request: Promise<any>, message?: string): boolean

del

  • del(urlOrApiInfo: string | ApiInfo, init: any): any
  • DELETE HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

endpoint

  • endpoint(apiName: string): string

get

  • get(urlOrApiInfo: string | ApiInfo, init: any): any
  • GET HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

getCancellableToken

  • getCancellableToken(): CancelTokenSource

hasCancelToken

  • hasCancelToken(request: Promise<any>): boolean
  • Check if the request has a corresponding cancel token in the WeakMap.

    params

    request - The request promise

    Parameters

    Returns boolean

    if the request has a corresponding cancel token.

head

  • head(urlOrApiInfo: string | ApiInfo, init: any): any
  • HEAD HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

isCancel

  • isCancel(error: any): boolean
  • Checks to see if an error thrown is from an api request cancellation

    Parameters

    • error: any

      Any error

    Returns boolean

    • A boolean indicating if the error was from an api request cancellation

patch

  • patch(urlOrApiInfo: string | ApiInfo, init: any): any
  • PATCH HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

post

  • post(urlOrApiInfo: string | ApiInfo, init: any): any
  • POST HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

put

  • put(urlOrApiInfo: string | ApiInfo, init: any): any
  • PUT HTTP request

    Parameters

    • urlOrApiInfo: string | ApiInfo

      Full request URL or Api information

    • init: any

      Request extra params

    Returns any

    • A promise that resolves to an object with response status and JSON data, if successful.

updateRequestToBeCancellable

  • updateRequestToBeCancellable(promise: Promise<any>, cancelTokenSource: CancelTokenSource): void
  • Updates the weakmap with a response promise and its cancel token such that the cancel token can be easily retrieved (and used for cancelling the request)

    Parameters

    • promise: Promise<any>
    • cancelTokenSource: CancelTokenSource

    Returns void