Raw Fetch Mode
Use $fetch without a schema for a native Response, behaving like global fetch.
$fetch(input, options) behaves like native fetch and returns the Response.
import { $fetch } from "@zap-studio/fetch";
const response = await $fetch("https://api.example.com/health");
console.log(response.status);
console.log(response.headers.get("content-type"));
Use this mode for headers, status codes, streams, text, blobs, or any response that should not be parsed as JSON by the package. Non-2xx responses still throw a FetchError unless you set throwOnFetchError: false.
Signature
function $fetch(input: FetchInput, options?: ExtendedRequestInit): Promise<Response>;
input— astring,URL, orRequest, the same type as globalfetch. Exported asFetchInput.options— nativeRequestInitplus the extra options listed below. Exported asExtendedRequestInit.
When input is a Request, its headers are merged with per-request headers (per-request values win), and remaining options are applied on top:
import { $fetch } from "@zap-studio/fetch";
const request = new Request("https://api.example.com/users/1", {
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
},
});
const response = await $fetch(request);
Options
| Option | Type | Default | Description |
|---|---|---|---|
searchParams |
URLSearchParams init |
undefined |
Per-request query params, merged into the request URL. |
throwOnFetchError |
boolean |
true |
Throw a FetchError on non-2xx responses. |
Every standard RequestInit option (method, headers, body, signal, …) is also accepted.
See Also
- Validated Fetch Mode — parse and validate the JSON response instead.
- Structured Errors —
FetchErrordetails and catch patterns. - Overview — package summary and quick start.