@infrasoftbe/vnv-sdk
    Preparing search index...

    Function FetchFactory

    • Creates a reusable HTTP request function with predefined options.

      Type Parameters

      • DATA_TYPE

        The type of data that will be sent in the request

      • RETURN_DATA_TYPE

        The type of data that will be returned from the request

      Parameters

      • options: IFetchFactory

        Configuration options for the fetch factory

        Interface representing a fetch factory configuration.

        IFetchFactory

        • caller: Function

          The function used to perform the HTTP request.

        • Optionalformat?: false | "text" | "json" | "blob" | "stream"

          Optional response format. If false, raw response is returned.

        • Optionalheaders?: Record<string, string>

          Optional HTTP request headers.

        • method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE"

          The HTTP request method.

      Returns TFetchFactory<DATA_TYPE, RETURN_DATA_TYPE>

      A function that makes HTTP requests with the configured options The returned function accepts:

      • endpoint: URL to send the request to
      • data: Optional payload to send with the request
      const fetcher = FetchFactory<RequestType, ResponseType>({
      method: 'POST',
      caller: fetch,
      headers: { 'Content-Type': 'application/json' }
      });

      const response = await fetcher('/api/endpoint', data);