A fetch client with added resilience features.

interface FetchClient {
    abortAll(reason?: any): void;
    baseUrl(): undefined | string;
    close(options?: {
        timeout?: number;
    }): Promise<unknown>;
    fetch(input: RequestInfo | URL, init?: RequestInit & RequestOptions): Promise<Response>;
    fetchJson<T>(input: RequestInfo | URL, init?: RequestInit & JsonRequestOptions): Promise<JsonResult<T>>;
}

Hierarchy (view full)

Methods

  • Abort all ongoing requests.

    Parameters

    • Optionalreason: any

    Returns void

  • Retrieve the base url/prefix for all requests.

    Returns undefined | string

  • Close the client. It will not be possible to send new requests afterwards.

    Parameters

    • Optionaloptions: {
          timeout?: number;
      }

      if timeout is 0, all ongoing requests will be cancelled immediately. If timeout is > 0 and there are ongoing requests, they will be cancelled after timeout milliseconds. If not specified, ongoing requests will be awaited for indefinitely before closing.

      • Optionaltimeout?: number

    Returns Promise<unknown>

  • Similar to the global fetch function, but if configured so, with retry, timeout, circuit breaker and bulkhead capabilities. Unless the init.skipFailOnErrorCode flag is set, the promise will be rejected on status codes >= 400. This is different from standard fetch behaviour. Otherwise the API is the same.

    Parameters

    Returns Promise<Response>