Registry / serialization / zod-http-schemas

zod-http-schemas

JSON →
library2.0.5jsnpmunverified

Zod-powered HTTP schema library for strongly typed client-server communication. Version 2.0.5, stable. Combines runtime validation from zod with compile-time types for HTTP request and response shapes. Supports path parameters, request body, and response body schemas. Differentiates from plain zod by providing a unified schema definition for both client and server, automatic response trimming to prevent data leaks, and a client using Axios. Key differentiator: single source of truth for API contracts across client and server, with TypeScript type inference.

npm install zod-http-schemas
INSTALL
IMPORT
SIG · ZOD-HTTP-SCHEMAS
Z
zod-http-schemas
serializationjavascriptv2.0.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createHttpSchema
import { createHttpSchema } from 'zod-http-schemas'
const createHttpSchema = require('zod-http-schemas')
ESM-only package; requires CommonJS users to use dynamic import or esm.
createHttpClient
import { createHttpClient } from 'zod-http-schemas/client'
import { createHttpClient } from 'zod-http-schemas'
Client-related exports are only available from 'zod-http-schemas/client' subpath.
extractShape
import type { extractShape } from 'zod-http-schemas'
import { extractShape } from 'zod-http-schemas'
extractShape is a type-only export; use import type to avoid runtime import in bundlers.

Creates a shared HTTP schema and uses the client to make two typed requests.

import { createHttpSchema } from 'zod-http-schemas'; import { createHttpClient } from 'zod-http-schemas/client'; import { z } from 'zod'; const apiSchema = createHttpSchema({ 'GET /greet/:name': { responseBody: z.string(), }, 'POST /sum': { requestBody: z.array(z.number()), responseBody: z.number(), }, }); const client = createHttpClient(apiSchema, { baseURL: process.env.API_BASE ?? 'http://localhost:3000' }); async function main() { const greeting = await client.get('/greet/:name', { params: { name: 'World' } }); console.log(greeting); const sum = await client.post('/sum', { body: [1, 2, 3] }); console.log(sum); } main().catch(console.error);
Debug
Known issues
breakingVersion 2.x uses Axios as HTTP client; migrate from 1.x which used fetch.
fix
Update client configuration options to align with Axios: baseURL, headers, etc.
affects: >=2.0.0
deprecatedcreateHttpClient from 'zod-http-schemas' (root) is deprecated; use 'zod-http-schemas/client'.
fix
Change import to import { createHttpClient } from 'zod-http-schemas/client'.
affects: >=2.0.0
gotchaExtraneous response properties are stripped at runtime, which may remove expected fields if schema is incomplete.
fix
Ensure responseBody schema includes all properties you want to keep.
affects: >=0.1.0
gotchaPath parameters must exactly match the URL template; extra or missing params cause TypeScript errors.
fix
Verify route string has matching placeholders and params object keys.
affects: >=2.0.0
breakingZod v3 peer dependency; zod v2 schemas are incompatible.
fix
Upgrade to zod@^3 and update any custom schemas to zod v3 API.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'zod-http-schemas/client' or its corresponding type declarations.
TypeScript does not recognize the subpath export; tsconfig may not support exports field.
fix
Use TypeScript 4.7+ with moduleResolution 'node16' or 'bundler', or add a path mapping.
TypeError: zod_http_schemas.createHttpSchema is not a function
Using CommonJS require() on an ESM-only package.
fix
Switch to dynamic import: const { createHttpSchema } = await import('zod-http-schemas');
Property 'body' does not exist on type 'AxiosResponse<...>'.
Client returns full AxiosResponse; response body is under .data, not .body.
fix
Access response data via result.data instead of result.body in client code.
Upgrade
Version history
2.0.5latest on npm
Audit
Dependencies
zodrequiredPeer dependency for defining schema types
axiosoptionalUsed by the client side for HTTP requests
Agent activity
41 hits · last 30 days
node
34
OpenAI (training)
1
Resources
zod-http-schemas — npm install zod-http-schemas · libregistry