Skip to main content
Home

A type-safe fetch wrapper with Standard Schema validation.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
4 hours ago (0.4.0)
function createFetch
createFetch(factoryOptions?: CreateFetchOptions): { $fetch: $Fetch; api: ApiMethods; }

Creates a custom fetch instance with pre-configured defaults.

Use this factory to create API clients with a base URL, default headers, and other shared configuration. Each instance is independent.

Examples

import { z } from "zod"; import { createFetch } from "@zap-studio/fetch";

// Create a configured instance const { $fetch, api } = createFetch({ baseURL: "https://api.example.com", headers: { "Authorization": "Bearer token" }, });

const UserSchema = z.object({ id: z.number(), name: z.string() });

// Now use relative paths - baseURL is prepended automatically const user = await api.get("/users/1", UserSchema);

// Or use $fetch directly const response = await $fetch("/users", UserSchema, { method: "POST", body: { name: "John" } });

Parameters

optional
factoryOptions: CreateFetchOptions

Return Type

{ $fetch: $Fetch; api: ApiMethods; }

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";
or

Import directly with a jsr specifier

import { createFetch } from "jsr:@zap-studio/fetch";

Add Package

pnpm i jsr:@zap-studio/fetch
or (using pnpm 10.8 or older)
pnpm dlx jsr add @zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";

Add Package

yarn add jsr:@zap-studio/fetch
or (using Yarn 4.8 or older)
yarn dlx jsr add @zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";

Add Package

vlt install jsr:@zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";

Add Package

npx jsr add @zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";

Add Package

bunx jsr add @zap-studio/fetch

Import symbol

import { createFetch } from "@zap-studio/fetch";