This function is a generic API handler that fetches data from a specified path using the Fetch API. It provides options for customizing the fetch request, handling loading state, aborting the request, and error handling.

  • Type Parameters

    • Data extends unknown = any

      The type of the data returned from the API

    Parameters

    • path: string

      The relative or absolute path to fetch from

    • Optionaloptions: IApiHandlerParams<Data>

      An object containing optional configuration options for the API handler

      Represents the parameters for an API handler.

      • OptionalabortSignal?: AbortSignal
      • Optionalfallback?: (e: Error) => void
      • Optionalfetch?: (input: URL | RequestInfo, init?: RequestInit) => Promise<Response> & (
            input: URL | RequestInfo,
            init?: RequestInit,
        ) => Promise<Response>
      • OptionalfetchParams?: () => RequestInit
      • OptionalonLoadBegin?: () => void
      • OptionalonLoadEnd?: (isOk: boolean) => void
      • Optionalorigin?: string
      • OptionalrequestMap?: (url: URL) => URL
      • OptionalresponseMap?: (json: Data) => Record<string, any> | Promise<Record<string, any>>
      • OptionalwithAbortSignal?: boolean

    Returns OneHandler<Data>

    • The API handler function that can be invoked to make the request and retrieve the data