Object with parameter name-value pairs. See QueryParamEntries.
Optionaloptions: QueryParamsOptionsOptional configuration. See QueryParamsOptions.
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=barrayFormat: 'brackets': { tags: ["a", "b"] } → ?tags[]=a&tags[]=bMerge behavior:
{} passes request through unchangedInput handling:
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
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.