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
a week ago (0.3.1)

@zap-studio/fetch

A type-safe fetch wrapper with Standard Schema validation.

Why @zap-studio/fetch?

Before:

const response = await fetch("/api/users/1");
const data = await response.json();
const user = data as User; // 😱 Unsafe type assertion

After:

const user = await api.get("/api/users/1", UserSchema);
// ✨ Typed, validated, and safe!

Features

  • 🎯 Type-safe requests with automatic type inference
  • 🛡️ Runtime validation using Standard Schema (Zod, Valibot, ArkType, etc.)
  • ⚡️ Convenient API methods (GET, POST, PUT, PATCH, DELETE)
  • 🏭 Factory pattern for creating pre-configured instances with base URLs
  • 🚨 Custom error handling with FetchError and ValidationError classes
  • 📘 Full TypeScript support with zero configuration

Installation

pnpm add @zap-studio/fetch
# or
npm install @zap-studio/fetch

Quick Start

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

// Define your schema
const UserSchema = z.object({
  id: z.number(),
  name: z.string(),
  email: z.email(),
});

// Make a type-safe request
const user = await api.get("https://api.example.com/users/1", UserSchema);

// user is fully typed and validated! ✨
console.log(user.name); // TypeScript knows this is a string

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 * as fetch from "@zap-studio/fetch";
or

Import directly with a jsr specifier

import * as fetch 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 * as fetch 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 * as fetch from "@zap-studio/fetch";

Add Package

vlt install jsr:@zap-studio/fetch

Import symbol

import * as fetch from "@zap-studio/fetch";

Add Package

npx jsr add @zap-studio/fetch

Import symbol

import * as fetch from "@zap-studio/fetch";

Add Package

bunx jsr add @zap-studio/fetch

Import symbol

import * as fetch from "@zap-studio/fetch";