Data Models
Models define the shape and structure of the data your mock API returns. Each model contains a set of typed properties that MockAPI uses to generate realistic responses.
What is a Data Model?
A data model is a blueprint for the objects your API returns. When a request hits a mock endpoint, MockAPI looks at the model associated with the response and generates data based on the property types you've defined. For example, a "User" model with properties for name, email, and avatar will produce realistic user objects every time.
Models are project-scoped. Each project has its own set of models that can be reused across multiple REST endpoints and GraphQL operations.
Creating a Model
Navigate to Models in the sidebar and click "New Model".
- Name (required): A unique name for the model (e.g., "User", "Product", "Order")
- Properties: Add one or more properties to define the model's data structure
Model Properties
Each property in a model has a name and a type. The type determines what kind of data MockAPI generates for that property. There are 140+ built-in types covering names, addresses, dates, numbers, images, and more. See Data Generation for the full list of available types.
Property configuration
Every property has the following configurable fields:
| Field | Description |
|---|---|
| Name | The JSON field name in generated responses (e.g., "firstName", "email") |
| Type | The data generation type (e.g., "First Name", "Email", "Number"). See Data Generation for the full list. |
| Sequential | When enabled, generates incrementing values (useful for IDs). Starts from 1 or a custom start value. |
| Range | When enabled, generates an array of values instead of a single value. Set the array size. |
| Range Start / End | For numeric types, generates a random number within this range. |
| Static Data | Returns a fixed value instead of generated data. |
| Custom List | Returns a random value from a custom list you define. |
| Regex Pattern | Generates strings matching a regular expression pattern. |
| Character Sequence | Generates strings based on a character pattern (see below). |
Character sequences
Character sequences let you define patterns for generated strings using special characters:
| Character | Generates |
|---|---|
| # | A random digit (0-9) |
| @ | A random uppercase letter (A-Z) |
| ^ | A random lowercase letter (a-z) |
| * | A random alphanumeric character |
| $ | A random special character |
| % | A random hexadecimal character (0-F) |
For example, the pattern SKU-####-@@ might generate SKU-4829-KM.
Static data
If you need a property to always return the same value, enable Static Data and enter the value. This is useful for constant fields like API version numbers or status strings.
{
"version": "2.0",
"status": "active"
}Custom list values
Custom lists let you define a set of possible values for a property. MockAPI randomly picks from the list for each generated instance. Enter values as a comma-separated list.
For example, for a "status" property, you might define: active, inactive, pending, suspended
Model Relationships
Models can reference other models to create nested structures. When a property's type is set to another model (e.g., model::ModelId), MockAPI generates a nested object using that model's properties.
// "Order" model with a nested "User" model
{
"id": 1,
"total": 99.99,
"customer": {
"id": 42,
"firstName": "Jane",
"lastName": "Smith",
"email": "jane.smith@example.com"
}
}Circular reference protection
MockAPI includes automatic circular reference detection. If Model A references Model B, and Model B references Model A, the system prevents infinite loops by limiting nesting depth to 5 levels. You can use the cycle detection checker when editing models to verify there are no problematic circular dependencies.
AI-Powered Property Types
Paid Plans Only
AI property type auto-assignment is available on Developer plans and above. See Plans & Billing for details.
When creating a model, you can enable AI auto-assign property types. MockAPI uses AI to analyze your property names and automatically select the most appropriate data generation type. For example, a property named "email" would be assigned the "Email" type, while "phoneNumber" would be assigned "Phone".
This feature is especially useful when importing models or creating many properties at once. It saves you from manually selecting types for each property.
Previewing Sample Data
After saving a model, you can preview the data MockAPI will generate by viewing the model's detail page. This shows a sample JSON object generated from your model's property configuration, letting you verify everything looks correct before wiring it up to endpoints.
Batch Operations
You can create or delete multiple models at once using batch operations. This is particularly useful when importing from external API definitions where many models need to be created simultaneously.
Managing Models
- Search: Filter models by name using the search bar on the models list page
- Edit: Click a model to view its details, then click "Edit" to modify properties
- Delete: Delete a model from its detail page (deletion is permanent)
- Pagination: Models are paginated with 25 items per page by default
Warning
Deleting a model does not automatically remove references to it from endpoints or GraphQL operations. You should update or remove any endpoint responses that reference a deleted model.