Pacote
    Preparing search index...

    Function createFetch

    • Creates a fetch function that returns a lazy TaskEither instead of rejecting for network, HTTP status, or response parsing failures.

      Successful response bodies are parsed as JSON when the content type is JSON, and as text otherwise. parse and parseLeft can replace these defaults. The fetch implementation can also be supplied for environments without a global Fetch API. The returned function produces a lazy TaskEither; calling it with () performs the request. The resolved Either contains either the parsed body or a typed network, status, or parser error, so it can be composed with fp-ts mapping functions without a try ... catch around each request.

      Type Parameters

      • E

        Parsed error response body type.

      • T

        Parsed successful response body type.

      Parameters

      • Optionaloptions: Partial<FetchOptions<E, T>>

        Optional Fetch API implementation and response parsers.

      Returns Fetch<E, T>

      A function that accepts Fetch API input and returns a TaskEither.

      const binaryFetch = createFetch({ parse: (response) => response.blob() })
      const result = await binaryFetch('/image.png')()