Class HTTPClient

HTTPClient is a wrapper around a BaseHTTPClient It takes care of setting the proper "Accept" header and of decoding the JSON outputs.

Hierarchy

  • HTTPClient

Constructors

Properties

Methods

  • Send a DELETE request. If no content-type present, adds the header "content-type: application/json" and data is serialized in JSON (if not empty)

    Parameters

    • relativePath: string
    • data: any
    • requestHeaders: Record<string, string> = {}
    • parseBody: boolean = true

    Returns Promise<HTTPClientResponse>

  • Send a GET request.

    Returns

    Response object.

    Parameters

    • relativePath: string

      The path of the request.

    • Optional query: Query<any>

      An object containing the query parameters of the request.

    • requestHeaders: Record<string, string> = {}

      An object containing additional request headers to use.

    • jsonOptions: JSONOptions = {}

      Options object to use to decode JSON responses. See utils.parseJSON for the options available.

    • parseBody: boolean = true

      An optional boolean indicating whether the response body should be parsed or not.

    Returns Promise<HTTPClientResponse>

  • Send a POST request. If no content-type present, adds the header "content-type: application/json" and data is serialized in JSON (if not empty)

    Parameters

    • relativePath: string
    • data: any
    • requestHeaders: Record<string, string> = {}
    • Optional query: Query<any>
    • parseBody: boolean = true

    Returns Promise<HTTPClientResponse>

  • Parse JSON using either the built-in JSON.parse or utils.parseJSON depending on whether jsonOptions are provided or not

    Parameters

    • text: string

      JSON data

    • status: number

      Status of the response (used in case parseJSON fails)

    • jsonOptions: JSONOptions = {}

      Options object to use to decode JSON responses. See utils.parseJSON for the options available.

    Returns any

  • Private

    Prepare an error with a response (the type of errors BaseHTTPClient are supposed to throw) by adding the status and preparing the internal response

    Parameters

    • err: any

    Returns any

  • Private

    Serialize the data according to the requestHeaders Assumes that requestHeaders contain a key "content-type" If the content-type is "application/json", data is JSON serialized Otherwise, data needs to be either an UTF-8 string that is converted to an Uint8Array or an Uint8Array

    Parameters

    • data: object
    • requestHeaders: Record<string, string>

    Returns Uint8Array

Generated using TypeDoc