{"id":18947,"library":"zod-http-schemas","title":"zod-http-schemas","description":"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.","status":"active","version":"2.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/antman261/zod-http-schemas","tags":["javascript","zod","express","api","schemas","runtime types","backend","typescript"],"install":[{"cmd":"npm install zod-http-schemas","lang":"bash","label":"npm"},{"cmd":"yarn add zod-http-schemas","lang":"bash","label":"yarn"},{"cmd":"pnpm add zod-http-schemas","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for defining schema types","package":"zod","optional":false},{"reason":"Used by the client side for HTTP requests","package":"axios","optional":true}],"imports":[{"note":"ESM-only package; requires CommonJS users to use dynamic import or esm.","wrong":"const createHttpSchema = require('zod-http-schemas')","symbol":"createHttpSchema","correct":"import { createHttpSchema } from 'zod-http-schemas'"},{"note":"Client-related exports are only available from 'zod-http-schemas/client' subpath.","wrong":"import { createHttpClient } from 'zod-http-schemas'","symbol":"createHttpClient","correct":"import { createHttpClient } from 'zod-http-schemas/client'"},{"note":"extractShape is a type-only export; use import type to avoid runtime import in bundlers.","wrong":"import { extractShape } from 'zod-http-schemas'","symbol":"extractShape","correct":"import type { extractShape } from 'zod-http-schemas'"}],"quickstart":{"code":"import { createHttpSchema } from 'zod-http-schemas';\nimport { createHttpClient } from 'zod-http-schemas/client';\nimport { z } from 'zod';\n\nconst apiSchema = createHttpSchema({\n  'GET /greet/:name': {\n    responseBody: z.string(),\n  },\n  'POST /sum': {\n    requestBody: z.array(z.number()),\n    responseBody: z.number(),\n  },\n});\n\nconst client = createHttpClient(apiSchema, { baseURL: process.env.API_BASE ?? 'http://localhost:3000' });\n\nasync function main() {\n  const greeting = await client.get('/greet/:name', { params: { name: 'World' } });\n  console.log(greeting);\n  const sum = await client.post('/sum', { body: [1, 2, 3] });\n  console.log(sum);\n}\nmain().catch(console.error);","lang":"typescript","description":"Creates a shared HTTP schema and uses the client to make two typed requests."},"warnings":[{"fix":"Update client configuration options to align with Axios: baseURL, headers, etc.","message":"Version 2.x uses Axios as HTTP client; migrate from 1.x which used fetch.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Change import to import { createHttpClient } from 'zod-http-schemas/client'.","message":"createHttpClient from 'zod-http-schemas' (root) is deprecated; use 'zod-http-schemas/client'.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure responseBody schema includes all properties you want to keep.","message":"Extraneous response properties are stripped at runtime, which may remove expected fields if schema is incomplete.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Verify route string has matching placeholders and params object keys.","message":"Path parameters must exactly match the URL template; extra or missing params cause TypeScript errors.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Upgrade to zod@^3 and update any custom schemas to zod v3 API.","message":"Zod v3 peer dependency; zod v2 schemas are incompatible.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use TypeScript 4.7+ with moduleResolution 'node16' or 'bundler', or add a path mapping.","cause":"TypeScript does not recognize the subpath export; tsconfig may not support exports field.","error":"Cannot find module 'zod-http-schemas/client' or its corresponding type declarations."},{"fix":"Switch to dynamic import: const { createHttpSchema } = await import('zod-http-schemas');","cause":"Using CommonJS require() on an ESM-only package.","error":"TypeError: zod_http_schemas.createHttpSchema is not a function"},{"fix":"Access response data via result.data instead of result.body in client code.","cause":"Client returns full AxiosResponse; response body is under .data, not .body.","error":"Property 'body' does not exist on type 'AxiosResponse<...>'."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}