Skip to main content

Overview

typed-api-spec is an TypeScript based declarative API specification.

Features

TypeScript based API Specification

You can define your API specification using TypeScript. No need to use yaml, json, or any other format.

type Spec = DefineApiEndpoints<{
"/users": {
get: {
responses: { 200: { body: { userNames: string[] }; }; };
};
};
}>;

See API Specification page for more details.

Type-safe, zero-runtime API client

typed-api-spec provides strict typed fetch. For example, if you define API response schema by API Specification, you can get the typed response data. It is just native fetch, so:

  • zero runtime: 0kb bundle size
  • zero dependencies
  • zero learning cost
const fetchT = fetch as FetchT<"", Spec>;
const res = await fetchT("/users");
const data = await res.json(); // data is { userNames: string[] }

See Client page for more details.

Server Framework & Validation library integration

typed-api-spec can be integrated with various server frameworks(like Express, Fastify) and validation libraries(like zod, Valibot).

See Server and Validation page for more details.