Schema guide

Create Mock APIs from TypeScript Schemas

Mock API Studio reads serializable TypeScript interfaces, type aliases, and enums and turns an exported response type into a mock REST resource. Define the contract in the model workspace, validate it, and bind the exported type to an endpoint before starting the local runtime.

Which TypeScript types can define a mock API?

Use interfaces, type aliases, string enums, primitive fields, arrays, nested object literals, optional fields, nullable fields, and supported unions. Multi-file projects can use relative imports and re-exports, while external packages and executable declarations are intentionally rejected.

TypeScript
export interface Product {
  id: string;
  name: string;
  price: number;
  status: "draft" | "active";
  tags?: string[];
}

export type ProductResponse = Product[];

Create or import model files

Create .ts files in the project model workspace or import a file tree. Imports keep project-relative paths. The browser editor reports TypeScript diagnostics, while server validation remains authoritative before a model is used.

  • Keep domain models in focused files.
  • Export every type that must be available to an endpoint binding.
  • Use exact filename casing because project paths are case-sensitive.

Bind a response type to an endpoint

Choose the source file and exported type in the endpoint editor, then select collection or single-object response shape. This explicit binding avoids guessing which declaration represents the response.

Configuration
Route: /products
Source: models/product.ts
Export: Product
Response shape: collection
Operations: GET, POST, PATCH, DELETE

Validate before local synchronization

Validation catches missing exports, invalid generic arguments, unsupported recursion, index signatures, and endpoint settings that reference unavailable fields. Resolve errors before restarting the CLI; the local runtime synchronizes the current valid project definition.

Related questions

Does Mock API Studio execute submitted TypeScript?

No. It analyzes declarations without emitting or evaluating JavaScript, and rejects executable declarations and side-effect imports.

Keep exploring

Last updated September 17, 2026. Product behavior described here is verified against the current Mock API Studio runtime.