Strongly-typed HTTP schemas for TypeScript that enforce API contracts at build time and runtime. Version 0.13.2 ships TypeScript types and integrates with the rtti library for schema specification and enforcement. It supports both client-side (createHttpClient) and server-side (Express integration with createRequestHandler and decorateExpressRouter) usage. Key differentiators include static type checking of request/response payloads, runtime validation, and automatic response trimming to prevent information leaks. Release cadence is irregular; the v0.10 API is deprecated but still supported. Alternatives like tRPC and Zod offer similar functionality but with different trade-offs.
npm install http-schemasVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining an HTTP schema with createHttpSchema and using createHttpClient to make typed requests.
Migrate to the v0.11+ API: use createHttpSchema instead of the old API.
Be aware that response objects will have only the properties defined in the schema.
Update server code to use decorateExpressRouter and createRequestHandler as shown in the README.
Ensure that requestBody and responseBody use valid `t` types (e.g., t.number, t.string, t.array, t.object).
Always provide a baseURL option when creating a client, or ensure the schema includes full URLs.
Wrap API calls in try/catch and handle validation errors from http-schemas.
Ensure the body matches the schema: client.post('/sum', { body: [1,2] }).Correct the type of the argument to match the schema definition.
Use import { createHttpClient } from 'http-schemas/client'.