The query parameter name
The query parameter value or array of values (encoded via URLSearchParams)
Optionaloptions: QueryParamsOptionsOptional configuration. See QueryParamsOptions.
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=barrayFormat: 'brackets': ["a", "b"] → ?tags[]=a&tags[]=bMerge behavior:
Input handling:
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
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.