Registry / http-networking / http-schemas

http-schemas

JSON →
library0.13.2jsnpmunverified

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-schemas
INSTALL
IMPORT
SIG · HTTP-SCHEMAS
H
http-schemas
http-networkingjavascriptv0.13.2
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 'http-schemas'
import httpSchemas from 'http-schemas'
createHttpSchema is a named export from the main package.
createHttpClient
import { createHttpClient } from 'http-schemas/client'
import { createHttpClient } from 'http-schemas'
createHttpClient is exported from the client subpath, not the main entry.
createRequestHandler
import { createRequestHandler } from 'http-schemas/server'
const createRequestHandler = require('http-schemas/server').createRequestHandler
In CommonJS, use require but ensure it's from the server subpath.
decorateExpressRouter
import { decorateExpressRouter } from 'http-schemas/server'
import { decorateExpressRouter } from 'http-schemas'
decorateExpressRouter is exported from the server subpath.
t
import { t } from 'http-schemas'
import { t } from 'rtti'
t is re-exported from http-schemas for convenience when defining schemas.

Demonstrates defining an HTTP schema with createHttpSchema and using createHttpClient to make typed requests.

import { createHttpSchema, t } from 'http-schemas'; import { createHttpClient } from 'http-schemas/client'; // Define a shared schema const apiSchema = createHttpSchema({ 'POST /sum': { requestBody: t.array(t.number), responseBody: t.number, }, 'GET /greet/:name': { responseBody: t.string, }, }); // Create a client const client = createHttpClient(apiSchema, { baseURL: 'https://api.example.com' }); // Use the client async function main() { const sum = await client.post('/sum', { body: [1, 2, 3] }); console.log(sum); // 6 const greeting = await client.get('/greet/:name', { params: { name: 'World' } }); console.log(greeting); // Hello, World! } main().catch(console.error);
Debug
Known issues
deprecatedThe v0.10 API is deprecated but still supported.
fix
Migrate to the v0.11+ API: use createHttpSchema instead of the old API.
affects: >=0.11.0
gotchaResponse payloads are trimmed of excess properties at runtime to prevent information leaks.
fix
Be aware that response objects will have only the properties defined in the schema.
affects: >=0.1.0
breakingThe v0.10 API for server-side code is deprecated; decorateExpressRouter and createRequestHandler are the new way.
fix
Update server code to use decorateExpressRouter and createRequestHandler as shown in the README.
affects: >=0.11.0
gotchaThe schema definition uses the `t` object from `rtti`. Incorrect usage can lead to runtime validation failures.
fix
Ensure that requestBody and responseBody use valid `t` types (e.g., t.number, t.string, t.array, t.object).
affects: >=0.1.0
gotchacreateHttpClient instances are cheap to create but require a baseURL; missing baseURL will cause runtime errors.
fix
Always provide a baseURL option when creating a client, or ensure the schema includes full URLs.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'reduce')
The request body is undefined or not the expected type because the schema validation failed but error handling is missing.
fix
Wrap API calls in try/catch and handle validation errors from http-schemas.
Error: Schema validation failed: request body is not an array
The request body sent to a POST /sum endpoint is not an array of numbers.
fix
Ensure the body matches the schema: client.post('/sum', { body: [1,2] }).
TS2322: Type 'string' is not assignable to type 'number'
The static type checking from http-schemas catches mismatches between schema and usage.
fix
Correct the type of the argument to match the schema definition.
Error: Cannot find module 'http-schemas/client'
Import path is incorrect; http-schemas uses subpath exports.
fix
Use import { createHttpClient } from 'http-schemas/client'.
Upgrade
Version history
0.13.2latest on npm
Audit
Dependencies
rttirequiredUsed for schema definition and runtime validation.
Agent activity
10 hits · last 30 days
node
10
Resources
http-schemas — npm install http-schemas · libregistry