Skip to content
Zap Studio
fetch
Esc
navigateopen⌘Jpreview
On this page

Getting Started

Install @zap-studio/fetch and make your first validated request.

Installation

npm install @zap-studio/fetch
yarn add @zap-studio/fetch
pnpm add @zap-studio/fetch
bun add @zap-studio/fetch
deno add jsr:@zap-studio/fetch

You also need a schema library that implements Standard Schema, such as Zod, Valibot, or ArkType. The examples below use Zod.

Make Your First Request

Define a schema for the response shape, then pass it to api.get.

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

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

const user = await api.get("https://api.example.com/users/1", UserSchema);

console.log(user.name); // typed as string, validated at runtime

The response is parsed and validated at runtime, and user is typed from UserSchema — no manual type annotations or as casts.

Handle Errors

api.get throws FetchError for non-2xx responses and ValidationError when the response doesn’t match the schema.

import { FetchError } from "@zap-studio/fetch";
import { ValidationError } from "@zap-studio/validation";

try {
  const user = await api.get("https://api.example.com/users/1", UserSchema);
  console.log(user);
} catch (error) {
  if (error instanceof FetchError) console.error(error.status);
  if (error instanceof ValidationError) console.error(error.issues);
}

Next Steps

Last updated on September 15, 2026

Was this page helpful?