Skip to content

itty-specContract-first, type-safe API definitions

for itty-router

What this project provides

  • Contract-first API design: define routes, inputs, and outputs once.
  • Fully typed TypeScript experience: complete type inference from contract to handler, with compile-time guarantees for request/response shapes.
  • Runtime validation: invalid requests are rejected before your handler runs, using Standard Schema V1 compatible validators.
  • End-to-end TypeScript inference: handlers receive typed, validated data (validatedParams, validatedQuery, validatedBody, validatedHeaders).
  • Typed response builder: responses must match the contract (status/content-type/body) - TypeScript errors catch mismatches at compile time.
  • Fetch-first compatibility: works in any environment that supports the Fetch API.
  • OpenAPI generation and serving: generate and serve OpenAPI 3.1 specifications from the same contract using @standard-community/standard-openapi.

What this project is not

  • Not a full application framework (no controllers, DI container, ORM, etc.).
  • Not a server runtime (you bring your own deployment: Workers, Node, Bun, Deno, etc.).
  • Not a replacement for itty-router; it builds on it.

Foundation

itty-spec is built on a lightweight foundation of battle-tested libraries:

  • itty-router (v5): The tiny router for Fetch that powers routing and request handling.
  • Standard Schema V1 (@standard-schema/spec): Provides a common interface for schema validation, enabling compatibility with multiple schema libraries.
  • Standard Community OpenAPI (@standard-community/standard-openapi): Converts Standard Schema V1 schemas to OpenAPI 3.1 format for documentation and tooling.

This architecture ensures minimal bundle size while providing maximum type safety and developer experience. The library is designed to work seamlessly in edge/serverless environments where every byte counts.

Released under the MIT License.