qfetch
    Preparing search index...
    • Middleware that adds a single query parameter to outgoing fetch requests.

      Sets a default query parameter on outgoing requests. Request parameters take precedence over middleware parameters when both exist.

      Parameters

      Returns MiddlewareExecutor

      A fetch executor that adds the query parameter to requests

      URL encoding: Values are encoded using the standard URLSearchParams API, which follows the application/x-www-form-urlencoded format.

      Array handling:

      • arrayFormat: 'repeat' (default): ["a", "b"]?tags=a&tags=b
      • arrayFormat: 'brackets': ["a", "b"]?tags[]=a&tags[]=b
      • Empty arrays are skipped entirely

      Merge behavior:

      • Middleware params are set first as defaults
      • Request params are appended after (taking precedence)
      • Both values are kept when keys overlap (request value appears later)

      Input handling:

      • String inputs: Returns modified string (preserves relative/absolute)
      • URL inputs: Returns new URL object with modified searchParams
      • Request objects: Returns new Request with modified URL
      import { withQueryParam } from "@qfetch/middleware-query-params";

      // Basic usage with single value
      const qfetch = withQueryParam("page", "1")(fetch);
      await qfetch("https://api.example.com/users");
      // → https://api.example.com/users?page=1
      import { withQueryParam } from "@qfetch/middleware-query-params";

      // Array values with repeated keys (default)
      const qfetch = withQueryParam("tags", ["foo", "bar"])(fetch);
      await qfetch("https://api.example.com/posts");
      // → https://api.example.com/posts?tags=foo&tags=bar
      import { withQueryParam } from "@qfetch/middleware-query-params";

      // Array values with bracket notation
      const qfetch = withQueryParam("tags", ["foo", "bar"], { arrayFormat: "brackets" })(fetch);
      await qfetch("https://api.example.com/posts");
      // → https://api.example.com/posts?tags[]=foo&tags[]=bar
      import { withQueryParam } from "@qfetch/middleware-query-params";
      import { compose } from "@qfetch/core";

      // Composition with multiple params
      const qfetch = compose(
      withQueryParam("page", "1"),
      withQueryParam("limit", "10")
      )(fetch);
      await qfetch("https://api.example.com/users");
      // → https://api.example.com/users?page=1&limit=10