Interface FetchClientCaching

A version of the FetchClient that supports caching responses (for the FetchClientCaching.fetchJson method, for now).

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

Hierarchy (view full)

Methods

  • 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>

  • Initiate a client request and at the same time lookup the value in the cache. The first returned value is reported as initialValue. The update promise throws NoUpdateError if only a single value could be retrieved, if both values are equal, or if the result of the fetch operation is retrieved first. If the result of the fetch operation comes in last and it differs from the cached result then it will reported via the update promise.

    Note that the return signature differs from the fetchJson method without cache configuration or other caching modes, due to the need to provide an update to the initially returned value.

    Type Parameters

    • T

    Parameters

    Returns Promise<JsonResult<T> & {
        update: Promise<JsonResult<T>>;
    }>

  • A convenience function to retrieve JSON data + headers. See fetch.

    Type Parameters

    • T

    Parameters

    Returns Promise<JsonResult<T>>