DEV Community

Cover image for How to Mock an API in Apidog Without Writing Any Code
Hassann
Hassann

Posted on • Originally published at apidog.com

How to Mock an API in Apidog Without Writing Any Code

Your frontend team is blocked: GET /users and GET /orders are not ready, but the UI needs realistic data for lists, pagination, loading states, and empty states. Hand-maintained JSON fixtures work briefly, then drift from the real API contract. If you already have an API specification, Apidog can generate a mock directly from each endpoint’s response schema with no mock-server code or configuration.

Try Apidog today

This feature, Smart Mock, uses property names and schema types to generate plausible values. For example, a name property can return a realistic name, while email returns an email-shaped value. This guide shows how to mock two e-commerce endpoints, call their mock URLs, control generated values, and understand response priority. For background, see what API mocking is and how it works and the JSON Schema documentation.

What Smart Mock does

Apidog supports several ways to generate mock responses:

  1. Smart Mock: generates data automatically from the API response schema.
  2. Response Example: returns an example defined in the endpoint specification.
  3. Custom Response: returns a manually configured response.
  4. Conditional Mocking: returns different responses based on request parameters.
  5. Mock Scripts: generates values related to the incoming request.

Apidog mock response options

Smart Mock is the zero-configuration option. Add a response schema to an endpoint, and Apidog fills its properties with generated data. If an endpoint does not have a predefined response example, Smart Mock can act as the fallback instead of returning an empty result.

For frontend work, this means the API schema becomes the source of truth for both the contract and the mock. Update a field in the schema, and the mock updates with it.

Prerequisite: define a response schema

Smart Mock requires a response definition on the endpoint.

If you design APIs in Apidog, add a response schema under the endpoint response definition. If you import an OpenAPI document, response schemas typically import with the endpoints.

Without a response schema, Smart Mock has no structure to generate from.

To use Local Mock, install the Apidog desktop client. Local Mock runs on your machine and is not available in Apidog Web. Download Apidog to follow along.

Step-by-step: mock GET /users and GET /orders

Use a small store API as an example.

Step 1: Define GET /users

Create a GET /users endpoint and add a response schema such as:

{
  "id": 1024,
  "name": "Amara Osei",
  "email": "amara.osei@example.com",
  "phone": "+1-415-555-0148",
  "createdAt": "2026-03-11T09:24:00Z",
  "isActive": true
}
Enter fullscreen mode Exit fullscreen mode

Make sure the schema declares property types:

  • id: integer
  • name, email, phone: string
  • createdAt: string, optionally with a date-time format
  • isActive: boolean

Step 2: Define GET /orders

Create GET /orders with an array response:

[
  {
    "orderId": "ORD-58210",
    "userId": 1024,
    "total": 84.5,
    "currency": "USD",
    "status": "shipped",
    "createdAt": "2026-05-02T14:03:00Z"
  }
]
Enter fullscreen mode Exit fullscreen mode

Use explicit types for every property. Smart Mock uses both property names and schema constraints to choose generated values.

Step 3: Copy the mock URL

Each endpoint receives a mock URL automatically.

  • In DESIGN mode, find it in the endpoint’s API tab.
  • In DEBUG mode, find it in the Mock tab.

Use Click to copy to copy the URL.

The copied value is only the URL. When calling non-GET endpoints, set the HTTP method and request body in your client.

A Local Mock URL uses 127.0.0.1:4523. In path mode, it looks like this:

http://127.0.0.1:4523/m1/{projectID}-{versionNo}-{serverNo}/users
Enter fullscreen mode Exit fullscreen mode

Apidog starts Local Mock automatically while the desktop client is open.

You can also target a specific endpoint using ID mode:

http://127.0.0.1:4523/m2/{projectID}-{versionNo}-{serverNo}/{endpointId}
Enter fullscreen mode Exit fullscreen mode

Step 4: Call the mock

Call GET /users with curl:

curl http://127.0.0.1:4523/m1/1234567-0-0/users
Enter fullscreen mode Exit fullscreen mode

Smart Mock can return a response similar to:

{
  "id": 3187,
  "name": "Diego Marchetti",
  "email": "diego.marchetti@example.net",
  "phone": "+1-628-555-0113",
  "createdAt": "2026-01-27T18:41:22Z",
  "isActive": true
}
Enter fullscreen mode Exit fullscreen mode

The name and email values are generated through property-name matching rather than random strings. Refresh the request to generate new dynamic values and test how the UI handles different content lengths and values.

Call the orders endpoint the same way:

curl http://127.0.0.1:4523/m1/1234567-0-0/orders
Enter fullscreen mode Exit fullscreen mode

You now have an array of generated order objects for an order-list UI.

How Smart Mock chooses values

Smart Mock uses a three-level priority order for each property:

  1. Mock Field
  2. Property Name Matching
  3. JSON Schema defaults and constraints

1. Mock Field

A property-level Mock Field has the highest priority.

Use one of these input types:

  • Fixed value: always return the same value.
  • Faker statement: return varied generated values.

For example, use a fixed value for a constant currency:

USD
Enter fullscreen mode Exit fullscreen mode

Or configure a Faker statement for status to return values such as:

shipped
pending
delivered
Enter fullscreen mode Exit fullscreen mode

2. Property Name Matching

If no Mock Field is configured, Smart Mock matches property names against built-in wildcard or regular-expression rules.

That is why fields such as email and createdAt can receive appropriate generated values. You can review or add rules in Mock Settings.

3. JSON Schema

If a property has no Mock Field and no matching property-name rule, Smart Mock falls back to its schema type and constraints.

For example, a string property with no matching name or extra constraints receives a generic string value.

Smart Mock configuration

Smart Mock respects JSON Schema constraints, including:

  • enum
  • string length
  • numeric minimum and maximum values
  • array minItems and related length constraints

For example:

{
  "type": "string",
  "enum": ["pending", "shipped", "delivered"]
}
Enter fullscreen mode Exit fullscreen mode

A status field with this schema only returns one of those three values.

You can also select mock locales to generate regionalized data. For example, switching to a Japanese locale changes generated names and addresses to match that format.

Fixing incorrect Smart Mock values

Smart Mock is schema-driven inference, so some field names may need more guidance.

For example:

  • sku may fall back to a generic string.
  • total may be generated as a number outside the range your UI expects.
  • A domain-specific identifier may not match a built-in name rule.

Apply these fixes in order.

Tighten the schema

Start by expressing the rule in JSON Schema.

For example:

{
  "type": "number",
  "minimum": 0,
  "maximum": 10000
}
Enter fullscreen mode Exit fullscreen mode

Use an enum for known states:

{
  "type": "string",
  "enum": ["pending", "paid", "shipped", "delivered"]
}
Enter fullscreen mode Exit fullscreen mode

Use a pattern for identifiers:

{
  "type": "string",
  "pattern": "^SKU-[A-Z0-9]{8}$"
}
Enter fullscreen mode Exit fullscreen mode

Schema constraints keep generated output within the expected shape without requiring custom mock values.

Set a Mock Field

Use a Mock Field when schema constraints are not enough.

Use a Fixed value when a property must never change:

USD
Enter fullscreen mode Exit fullscreen mode

Use a Faker statement when you need controlled variation.

Apidog’s Faker support follows ideas similar to the Mock.js library. See the guide to using Faker in Apidog for expression syntax.

Add a Property Name Matching rule

If the same field appears across multiple endpoints, add a reusable rule instead of configuring each property separately.

  1. Go to Settings.
  2. Open General Settings.
  3. Open Feature Settings.
  4. Open Mock Settings.
  5. Click New.
  6. Define a field-name condition and mock expression.

For example, add a rule for sku so every matching property uses your defined SKU pattern rather than a generic string.

Mock response priority: which response wins?

An endpoint can have a Mock Expectation, a Response Example, and Smart Mock available. Apidog resolves them using the Default mock method setting in Project Settings → Mock Settings.

Available modes:

  • Smart Mock First: Mock Expectation → Smart Mock
  • Response example first: Mock Expectation → Response Example → Smart Mock

Read the order from left to right.

Under the default Smart Mock First setting, Apidog first checks for a matching Mock Expectation. If none matches, Smart Mock generates the response.

Under Response example first, Apidog checks a Response Example before falling back to Smart Mock.

A matching Mock Expectation always has the highest priority. For example, you can configure a conditional 404 response when userId=9999, and it will override the other response methods. See mocking conditional API responses in Apidog for a parameter-driven workflow.

Local Mock, Cloud Mock, and Runner Mock

Smart Mock defines how a response is generated. Local, Cloud, and Runner Mock define where it runs.

  • Local Mock runs through the Apidog desktop client on your computer. It is reachable only while the client is open and listens on 127.0.0.1:4523. To access it from another device on your local network, use your machine’s LAN IP. It is not available in Apidog Web.
  • Cloud Mock runs on Apidog servers and is available 24/7. Enable it in environment management when teammates or deployed previews need access. Its URLs use https://mock.apidog.com with the same m1 and m2 path formats. It is intended for testing rather than production traffic.
  • Runner Mock is self-hosted on your team infrastructure, which is useful when the mock must stay within your own network.

Use:

  • Local Mock for individual frontend development.
  • Cloud Mock for shared or remote testing.
  • Runner Mock for self-hosted internal environments.

For more context, see the comparison of online API mocking tools and the Apidog Cloud Mock guide.

Routing gotchas

Keep these rules in mind when a mock endpoint does not route as expected.

Start endpoint paths with /

Use paths such as:

/orders
Enter fullscreen mode Exit fullscreen mode

A complete URL that does not begin with / does not use the mock environment. A path without a leading slash only works in ID mode.

Disambiguate duplicate method-and-path endpoints

If two endpoints share the same HTTP method and path, path mode cannot distinguish them automatically.

Add the endpoint ID as a query parameter:

?apidogApiId={endpointId}
Enter fullscreen mode Exit fullscreen mode

Refresh to regenerate dynamic data

Dynamic mock data regenerates when you refresh the request. If you receive the same generated body repeatedly, check whether your API client, browser, or UI is showing a cached response.

Automate contract checks with the Apidog CLI

The Apidog CLI does not start or host a mock server. Local, Cloud, and Runner Mock serve the responses.

The CLI helps keep the schema behind Smart Mock accurate as the API evolves. Because Smart Mock is generated from endpoint schemas, updating the specification updates the generated mock output.

The CLI and AI coding agents such as Cursor, Claude Code, Trae, and Codex can create and update endpoints and schemas in the project. Once frontend work is unblocked, run the project’s test scenarios in CI against the real backend using the same API contract.

apidog run -t <scenario_id> -e <env_id> -r html,cli
Enter fullscreen mode Exit fullscreen mode

Install and authenticate:

npm install -g apidog-cli
apidog login --with-token <your-token>
Enter fullscreen mode Exit fullscreen mode

The CLI requires Node.js v16 or later. See running Apidog in a CI/CD pipeline for setup details.

FAQ

Do I need to write code to use Smart Mock?

No. Define an endpoint response schema and Smart Mock generates data automatically. Use a Faker statement or mock script only when you need to override a specific value. See the mock API overview for the core concepts.

Why is my mock URL returning nothing?

First, verify that the endpoint has a response definition. Smart Mock needs a response schema. Also confirm that the path starts with / and, for Local Mock, that the Apidog desktop client is open.

How do I return a fixed value instead of generated data?

Set the property’s Mock Field to a Fixed value. Mock Fields have higher priority than property-name matching and schema defaults.

Can teammates access a mock running on my laptop?

Only over your local network and only while the Apidog client is running. Local Mock listens on 127.0.0.1:4523. For always-on shared access, enable Cloud Mock at https://mock.apidog.com.

Which response wins when both a Response Example and Smart Mock exist?

It depends on the Default mock method:

  • Smart Mock First uses Smart Mock after no Mock Expectation matches.
  • Response example first uses the Response Example before Smart Mock.

A matching Mock Expectation overrides both.

Wrap up

Smart Mock turns a response schema into a working API mock without hand-writing fixture files. Define the response schema, copy the endpoint mock URL, and call it from your frontend. When generated data needs adjustment, tighten the JSON Schema, configure a Mock Field, or add a reusable property-name rule.

Top comments (0)