qfetch
    Preparing search index...
    • Middleware that adds multiple query parameters to outgoing fetch requests.

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

      Parameters

      Returns MiddlewareExecutor

      A fetch executor that adds the query parameters 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): { tags: ["a", "b"] }?tags=a&tags=b
      • arrayFormat: 'brackets': { tags: ["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)
      • Empty params object {} passes request through unchanged

      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 { withQueryParams } from "@qfetch/middleware-query-params";

      // Basic usage with multiple params
      const qfetch = withQueryParams({
      page: "1",
      limit: "10",
      sort: "name"
      })(fetch);

      await qfetch("https://api.example.com/users");
      // → https://api.example.com/users?page=1&limit=10&sort=name
      import { withQueryParams } from "@qfetch/middleware-query-params";

      // Array values with repeated keys (default)
      const qfetch = withQueryParams({
      tags: ["typescript", "javascript"]
      })(fetch);

      await qfetch("https://api.example.com/posts");
      // → https://api.example.com/posts?tags=typescript&tags=javascript
      import { withQueryParams } from "@qfetch/middleware-query-params";

      // Array values with bracket notation
      const qfetch = withQueryParams(
      { tags: ["typescript", "javascript"] },
      { arrayFormat: 'brackets' }
      )(fetch);

      await qfetch("https://api.example.com/posts");
      // → https://api.example.com/posts?tags[]=typescript&tags[]=javascript
      import { withQueryParams } from "@qfetch/middleware-query-params";
      import { compose } from "@qfetch/core";

      // Composition with other middlewares
      const qfetch = compose(
      withQueryParams({ format: "json", version: "v2" }),
      withBaseUrl("https://api.example.com")
      )(fetch);

      await qfetch("/users");
      // → https://api.example.com/users?format=json&version=v2