The header name
The header value
A middleware executor that adds the header to requests
Header names: Case-insensitive per HTTP specification. Content-Type and
content-type are treated as the same header.
Merge behavior:
import { withHeader } from "@qfetch/middleware-headers";
// Add Content-Type header
const qfetch = withHeader("Content-Type", "application/json")(fetch);
await qfetch("https://api.example.com/users");
// Request includes: Content-Type: application/json
import { withHeader } from "@qfetch/middleware-headers";
import { compose } from "@qfetch/core";
// Compose multiple headers
const qfetch = compose(
withHeader("Content-Type", "application/json"),
withHeader("Accept", "application/json")
)(fetch);
import { withHeader } from "@qfetch/middleware-headers";
// Request headers take precedence
const qfetch = withHeader("Content-Type", "application/json")(fetch);
await qfetch("https://api.example.com/users", {
headers: { "Content-Type": "text/plain" }
});
// Request uses: Content-Type: text/plain (request value wins)
Middleware that adds a single header to outgoing fetch requests.
Sets a default header on outgoing requests. Request headers take precedence over middleware headers - if the same header already exists in the request, the middleware header is not applied.