API Academy
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
  1. Mocking APIs
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
๐ŸŒ English
  • ๐ŸŒ English
  • ๐ŸŒ ็น้ซ”ไธญๆ–‡
  1. Mocking APIs

Smart Mock

Smart Mock is Apidog's automatic mock data generation feature. It creates realistic mock responses based on your API specification without requiring any configuration. Simply define your API spec, and Apidog will intelligently generate appropriate mock data for you.
In this article, we'll learn how to use Smart Mock with the Pet Store API.

1. What Is Smart Mock?#

Smart Mock automatically generates mock data by analyzing your API specification. It recognizes common field names and generates appropriate dataโ€”no manual configuration needed.

Why Use Smart Mock?#

Works immediately: No setup requiredโ€”just define your API spec
Intelligent: Automatically recognizes field names and generates realistic data
Always valid: Respects your JSON Schema to ensure valid responses

2. How to Use Smart Mock#

Let's see how Smart Mock works with the Pet Store API:

Step 1: Open the Endpoint#

1.
Open the Pet Store API in your Apidog project
2.
Navigate to an endpoint (e.g., GET /pets/{id})
3.
Make sure the endpoint has a response schema defined

Step 2: Access the Mock Tab#

1.
Click the "Mock" tab (or switch to DEBUG mode and find the Mock section)
2.
You'll see the mock URL for this endpoint
image.png

Step 3: Copy and Use the Mock URL#

1.
Click the mock URL to copy it
2.
The URL will look something like: http://127.0.0.1:4523/m1/{project-id}/0/pets/{id}
3.
Paste it in your browser or use it in your application
4.
Replace path parameters (like {id}) with actual values

Step 4: View the Mock Response#

The mock server will return Smart Mock-generated data. For example:
{
  "id": "pet_123",
  "name": "Buddy",
  "species": "DOG",
  "breed": "Golden Retriever",
  "ageMonths": 24,
  "status": "AVAILABLE",
  "adoptionFee": 150.00
}
Each time you refresh or make a new request, Smart Mock will generate new data while respecting your schema constraints.

3. How Smart Mock Generates Data#

Smart Mock uses intelligent name matching to generate appropriate data. It recognizes common field names and generates realistic values.

Automatic Name Recognition#

Smart Mock automatically recognizes common field names:
name, firstName, lastName โ†’ Generates person names
email โ†’ Generates email addresses
phone, phoneNumber โ†’ Generates phone numbers
address, street โ†’ Generates addresses
price, amount, cost โ†’ Generates monetary values
id, userId โ†’ Generates IDs
createdAt, updatedAt โ†’ Generates timestamps

Example: Pet Store API#

In the Pet Store API's GET /pets/{id} response:
name โ†’ Smart Mock generates pet names like "Buddy" or "Luna"
species โ†’ Generates species values like "DOG" or "CAT"
breed โ†’ Generates breed names like "Golden Retriever"
ageMonths โ†’ Generates age values
status โ†’ Generates status values like "AVAILABLE"
If a field name doesn't match any pattern, Smart Mock generates a default value based on the field type (string, number, boolean, etc.).

4. Customizing Specific Fields#

Sometimes you want to control specific fields while letting Smart Mock handle the rest. You can do this using the mock field in your response schema.

Setting Fixed Values#

1.
Open your endpoint in the Edit tab
2.
Navigate to the Response section
3.
Find the property you want to customize
4.
Enter a value in the Mock field
Example: For the status field, you might set it to "AVAILABLE" to always return this status.

Using Dynamic Values#

You can also use Faker.js expressions to generate dynamic data:
{{$person.fullName}} โ†’ Generates random full names
{{$internet.email}} โ†’ Generates random email addresses
{{$number.int(min=1,max=100)}} โ†’ Generates numbers in a range
Example: For the name field, you could use {{$person.firstName}} to generate random first names.
image.png
When you set a value in the mock field, it overrides Smart Mock's automatic generation for that specific field.

5. JSON Schema Constraints#

Smart Mock respects all constraints defined in your JSON Schema. This ensures the generated data is always valid.

Common Constraints#

Enum values: If a field has specific allowed values, Smart Mock will pick one of them
Example: If status has enum ["AVAILABLE", "PENDING", "ADOPTED"], Smart Mock returns one of these values
Min/Max values: Number fields with min/max constraints generate values within those boundaries
Example: If ageMonths has minimum: 1 and maximum: 240, Smart Mock generates ages between 1 and 240
String length: String fields with length constraints generate strings within those limits
Array size: Array fields with item count constraints generate arrays with the appropriate number of elements

6. Key Takeaways#

Smart Mock automatically generates mock data from your API specification
Zero configuration requiredโ€”works immediately after defining your API spec
Intelligent name matching recognizes common field names and generates appropriate data
Mock field allows you to customize specific fields while using Smart Mock for the rest
JSON Schema constraints ensure all generated data is valid
Easy to useโ€”just copy the mock URL and start using it

Smart Mock makes it easy to get started with API mocking. Simply define your API specification, and Apidog will generate realistic mock data automatically. In the next article, we'll learn about Mock Expectationsโ€”how to create custom mock responses with conditions.
Continue with โ†’ Mock Expectations
Modified atย 2025-12-25 09:42:57
Previous
Mocking APIs: Overview
Next
Mock Expectations
Built with