The base URL to resolve against (string or URL instance).
Resolution behavior for string inputs:
"users") → resolved against the base URL"/users") → replaces the base pathname (keeps protocol + host)"https://other.com") → base URL is ignored entirelyTrailing slash matters: "https://api.example.com/v1/" (with slash) appends paths,
while "https://api.example.com/v1" (without slash) replaces the last segment.
Input type preservation: String inputs remain strings, URL objects remain URLs, and Request objects remain Requests.
import { withBaseUrl } from "@qfetch/middleware-base-url";
const qfetch = withBaseUrl("https://api.example.com/v1/")(fetch);
await qfetch("users"); // → https://api.example.com/v1/users
await qfetch("/users"); // → https://api.example.com/users
await qfetch("https://x.com"); // → https://x.com (base ignored)
Middleware that resolves string fetch requests against a base URL.
Resolves string request URLs against the provided base URL using the WHATWG URL Standard (
new URL(input, base)). URL and Request objects are passed through unchanged.