mini-effect
    Preparing search index...

    Function request

    • Creates an Effect that performs an HTTP request using the Fetch API.

      Parameters

      • input: string | URL

        The URL or Request to fetch

      • Optionalinit: RequestInit

        Optional RequestInit configuration (headers, method, body, etc.). The signal property is automatically set from the effect's abort signal.

      Returns Effect<Response, Failure<"FailedToFetch">, never, never>

      An Effect that resolves with a Response or fails with a FailedToFetch tagged error

      The request is cancellable — the effect's AbortSignal is forwarded to the underlying fetch() call. If the request fails (network error, DNS failure, etc.), the error is wrapped in a FailedToFetch tagged error that can be caught with catchTags.

      The returned effect resolves with the raw Response object. Use json, text, blob, bytes, or formData to read the response body.

      import { pipe, run } from "mini-effect";
      import { request, json } from "mini-effect/fetch";

      const data = await run(
      pipe(request("https://api.example.com/data"), (res) => json(res)),
      );