finds.dev

mattpocock/zod-fetch

Simple function for building a type-safe fetcher with Zod

View on GitHub

★ 691TypeScriptupdated May 2023

// the take

A thin wrapper that validates fetch responses against a Zod schema at runtime, giving you both type inference and runtime safety in one call. It's fetcher-agnostic — works with the native fetch API or axios or anything else. Useful for teams that want contract enforcement on external API calls without pulling in tRPC or a full HTTP client library.

The custom fetcher pattern is well-designed — by accepting any async function that returns data, it avoids coupling you to a specific HTTP library. TypeScript inference flows through correctly so the return type of your call matches the schema you passed in, not `unknown`. It's small enough to read and understand in five minutes, which matters when you need to debug a schema mismatch at 2am.

Last commit was May 2023 and Zod v4 dropped with breaking changes — this library hasn't been updated to match, so you're either pinned to Zod v3 or on your own. No error handling utilities: when validation fails you get a raw ZodError, and there's nothing here to help you distinguish a network failure from a schema mismatch. At 691 stars and 15 forks, adoption is thin enough that you'll be maintaining any bugs yourself. With 50 lines of source code, you could just write this yourself and own it.

We read the README, the directory tree and a key source file in June 2026. Nobody pays to be listed. How we judge →

// at a glance

Stars
691
Forks
15
Language
TypeScript
Last commit
27 May 2023

// nearby

If zod-fetch isn't quite it.

All repos →