Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface HttpClient

An interface used to interact with dfuse REST API.

Created mainly to abstract implementation details of dealing with HTTP request/response, enable consumer of the library to provide their own implementation of an HTTP client (think about providing Fetch interface instead).

group

Interfaces

Hierarchy

  • HttpClient

Index

Methods

apiRequest

  • Make an authenticated request (unauthenticated) to the dfuse REST endpoint.

    Upon a succesfull call, the actual response body (expected to be a valid JSON) will be returned to the caller.

    Upon an error, a DfuseError is returned, will be a DfuseApiError if the response's body exist, it's a valid JSON string and it fits the dfuse error format.

    Type parameters

    • T

    Parameters

    • apiToken: string

      The API token used to to interact with the API endpoint. The token will be turned into a proper HTTP header Authorization: Bearer ....

    • path: string

      (required) The HTTP path on the endpoint

    • method: string

      (required) The HTTP method to perform the request agaisnt

    • Optional params: HttpQueryParameters

      (defaults {}) The HTTP query parameters to append to the url, they will be url-encoded and included in the final remote url. Has no effect when empty or undefined.

    • Optional body: any

      (defaults undefined) The HTTP body to include in the request, assumed to be a JSON object that will be serialized to a string. Not included in the HTTP request when undefined.

    • Optional headers: HttpHeaders

      (defaults {}) The extra HTTP headers to include in the request. Those will be merged with default ones ({ Authorization: ... }) and they override them if same key are specified.

    Returns Promise<T>

    A Promise that will resolve to the response body if it passes. Will reject with a DfuseApiError if it fits the dfuse Error Format or a generic DfuseError is it's something not fitting our expected format.

authRequest

  • Make an anonymous request (unauthenticated) to the dfuse Authentication endpoint. Usually used only for issuing an API token from an API key.

    Type parameters

    • T

    Parameters

    • path: string

      (required) The HTTP path on the endpoint

    • method: string

      (required) The HTTP method to perform the request agaisnt

    • Optional params: HttpQueryParameters

      (defaults {}) The HTTP query parameters to append to the url, they will be url-encoded and included in the final remote url. Has no effect when empty or undefined.

    • Optional body: any

      (defaults undefined) The HTTP body to include in the request, assumed to be a JSON object that will be serialized to a string. Not included in the HTTP request when undefined.

    • Optional headers: HttpHeaders

      (defaults {}) The extra HTTP headers to include in the request. Those will be merged with default ones ({ Authorization: ... }) and they override them if same key are specified.

    Returns Promise<T>

    A Promise that will resolve to the response body if it passes. Will reject with a DfuseApiError if it fits the dfuse Error Format or a generic DfuseError is it's something not fitting our expected format.

release

  • release(): void
  • Release any resources hold by this HttpClient instance. Must be tolerant to being called multiple times.

    Once called, the instance is assumed unsuable and should never be invoked anymore.

    Returns void

Generated using TypeDoc