TypeScript-first models
Generate a mock API from your TypeScript interfaces
Mock API Studio lets developers add TypeScript interfaces and enums, map them to API resources, configure realistic behavior, and run the resulting mock backend locally through the npm runtime.
Can TypeScript interfaces generate a mock REST API?
Yes. Mock API Studio reads serializable TypeScript model declarations and uses a required response binding to decide whether an endpoint returns one record or a collection. This keeps the mock contract close to the types used by your application.
enum ProductStatus {
Active = "active",
Archived = "archived"
}
interface Product {
id: string;
name: string;
price: number;
categoryId: string;
status: ProductStatus;
}
type MockApiStudioResponse = Product[];How models become resources and records
Create an endpoint such as /products, then bind its response to Product[]. The local runtime parses the synchronized definition, generates values from field types and semantic names, and serves the records through enabled CRUD routes.
Names such as email, price, city, createdAt, and productName help the Faker-based generator select useful values. A project seed makes regeneration repeatable when the same schema and settings are used.
GET http://localhost:4000/products
{
"data": [{
"id": "63cd5cd0-2e08-4bb2-a253-6dc9ee9d8607",
"name": "Mechanical Keyboard",
"price": 89.99,
"categoryId": "category-1",
"status": "active"
}],
"meta": { "page": 1, "limit": 25, "total": 20, "totalPages": 1 }
}Validation before synchronization
The cloud model workspace runs TypeScript diagnostics and checks whether exported shapes can become JSON-like mock records. Errors identify the file, line, and unsupported expression before the project definition is accepted.
- Supported foundations include strings, numbers, booleans, optional fields, arrays, nested object literals, referenced interfaces, type aliases, and string-valued enums.
- Project-relative .ts imports can connect model files inside the same workspace.
- Function properties, conditional types, mapped types, import-type expressions, indexed access types, and non-string enums are rejected as non-mockable.
- Every endpoint needs a MockApiStudioResponse binding even when its model is declared in a shared file.
Use relationships for references
Keep related resources flat and configure the relationship in the project. For example, a Product can expose categoryId: string while a Category resource exposes id: string. During generation, the runtime fills child foreign keys from parent records so the initial dataset has no orphaned products.
Related questions
Does Mock API Studio support TypeScript enums?
Yes. Mockable enums must assign a string literal to every member. Numeric and computed enum members are not supported by the record generator.
Can definitions reference models in another file?
Yes. The model workspace supports project-relative TypeScript imports between files in the workspace. Imports that escape the workspace are rejected.
Are TypeScript errors detected before the runtime syncs?
The dashboard validates the model workspace and reports TypeScript and mockability diagnostics before saving an invalid definition.
Keep exploring
Last updated September 17, 2026. Product behavior described here is verified against the current Mock API Studio runtime.