Template Examples

Real-world examples for common API response patterns

1. User List API

Generate a list of users with realistic data using Faker and repeat loops

Use Case:

Mock API for user management dashboard, testing pagination, or user list components

Template:

User List Templatejson
{
  "success": true,
  "data": {
    "users": [
      {{#repeat 10}}
      {
        "id": {{@index 1}},
        "name": {{faker 'person.name'}},
        "email": {{faker 'email'}},
        "role": {{faker 'person.jobTitle'}},
        "avatar": {{faker 'image.avatar'}},
        "city": {{faker 'address.city'}},
        "country": {{faker 'address.country'}},
        "createdAt": {{faker 'date.dateInPast'}}
      }
      {{/repeat}}
    ],
    "total": 10,
    "page": 1,
    "perPage": 10
  }
}

Example Response:

Example Responsejson
{
  "success": true,
  "data": {
    "users": [
      {
        "id": 1,
        "name": "Jane Smith",
        "email": "jane.smith@example.com",
        "role": "Software Engineer",
        "avatar": "https://cloudflare-ipfs.com/ipfs/...",
        "city": "New York",
        "country": "United States",
        "createdAt": "2024-06-15T10:30:00.000Z"
      },
      {
        "id": 2,
        "name": "John Doe",
        "email": "john.doe@example.com",
        "role": "Product Manager",
        "avatar": "https://cloudflare-ipfs.com/ipfs/...",
        "city": "San Francisco",
        "country": "United States",
        "createdAt": "2024-05-20T14:15:00.000Z"
      }
      // ... 8 more users
    ],
    "total": 10,
    "page": 1,
    "perPage": 10
  }
}

2. Authentication Response

Create JWT tokens and user authentication responses

Use Case:

Mock login/signup endpoints, test authentication flows, JWT token management

Template:

Authentication Templatejson
{
  "success": true,
  "message": "Authentication successful",
  "data": {
    "user": {
      "id": {{faker 'datatype.number'}},
      "email": {{json 'email'}},
      "name": {{faker 'person.name'}},
      "avatar": {{faker 'image.avatar'}},
      "role": "user"
    },
    "tokens": {
      "accessToken": {{jwt 3600}},
      "refreshToken": {{jwt 604800}},
      "expiresIn": 3600,
      "tokenType": "Bearer"
    }
  }
}

Request Example:

Requesttext
POST /api/auth/login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Notes:

  • {{json "email"}} captures the email from request body
  • {{jwt 3600}} generates a JWT token that expires in 1 hour
  • Refresh token expires in 7 days (604800 seconds)

3. Paginated Data with Query Params

Handle pagination using query parameters and dynamic data

Use Case:

Test pagination components, infinite scroll, or data table loading

Template:

Pagination Templatejson
{
  "data": [
    {{#repeat 20}}
    {
      "id": {{@index 1}},
      "title": {{faker 'lorem.sentence'}},
      "description": {{faker 'lorem.paragraph'}},
      "author": {{faker 'person.name'}},
      "publishedAt": {{faker 'date.dateInPast'}}
    }
    {{/repeat}}
  ],
  "pagination": {
    "page": {{get 'page'}},
    "perPage": {{get 'perPage'}},
    "total": 200,
    "totalPages": 10,
    "hasNext": true,
    "hasPrev": false
  }
}

Request Example:

Requesttext
GET /api/posts?page=1&perPage=20

Response:

Example Responsejson
{
  "data": [
    {
      "id": 1,
      "title": "Lorem ipsum dolor sit amet.",
      "description": "Lorem ipsum dolor sit amet, consectetur...",
      "author": "Jane Smith",
      "publishedAt": "2024-08-15T10:30:00.000Z"
    }
    // ... 19 more items
  ],
  "pagination": {
    "page": 1,
    "perPage": 20,
    "total": 200,
    "totalPages": 10,
    "hasNext": true,
    "hasPrev": false
  }
}

4. Complex Nested Product Data

Create deeply nested data structures with multiple relationships

Use Case:

E-commerce product details, complex data hierarchies, nested relationships

Template:

Complex Product Templatejson
{
  "product": {
    "id": {{get 'id'}},
    "name": {{faker 'commerce.productName'}},
    "description": {{faker 'lorem.paragraph'}},
    "price": {{faker 'finance.amount'}},
    "currency": {{faker 'finance.currencyCode'}},
    "category": {{faker 'commerce.department'}},
    "inStock": true,
    "images": [
      {{#repeat 3}}
      {
        "id": {{@index 1}},
        "url": {{faker 'imageUrl'}},
        "alt": {{faker 'lorem.sentence'}}
      }
      {{/repeat}}
    ],
    "variants": [
      {{#repeat 5}}
      {
        "id": {{@index 100}},
        "name": {{faker 'commerce.productAdjective'}},
        "price": {{faker 'finance.amount'}},
        "sku": {{faker 'datatype.uuid'}}
      }
      {{/repeat}}
    ],
    "reviews": [
      {{#repeat 8}}
      {
        "id": {{@index 1}},
        "author": {{faker 'person.name'}},
        "rating": {{faker 'datatype.number'}},
        "comment": {{faker 'lorem.sentence'}},
        "createdAt": {{faker 'date.dateInPast'}}
      }
      {{/repeat}}
    ],
    "seller": {
      "id": {{faker 'datatype.number'}},
      "name": {{faker 'company.name'}},
      "email": {{faker 'email'}},
      "phone": {{faker 'phone.number'}},
      "address": {
        "street": {{faker 'address.street'}},
        "city": {{faker 'address.city'}},
        "state": {{faker 'address.state'}},
        "country": {{faker 'address.country'}},
        "postcode": {{faker 'address.postcode'}}
      }
    }
  }
}

Key Features:

  • Multiple nested arrays (images, variants, reviews)
  • Nested objects (seller with address)
  • Mix of request data and generated data
  • Different @index starting points for different arrays

5. Dynamic Search Results

Echo query parameters in response for search functionality

Use Case:

Search endpoints, filter testing, query echo patterns

Template:

Search Templatejson
{
  "query": {
    "search": {{get 'q'}},
    "category": {{get 'category'}},
    "minPrice": {{get 'minPrice'}},
    "maxPrice": {{get 'maxPrice'}}
  },
  "results": [
    {{#repeat 5}}
    {
      "id": {{@index 1}},
      "name": {{faker 'commerce.productName'}},
      "category": {{get 'category'}},
      "price": {{faker 'finance.amount'}},
      "description": {{faker 'lorem.sentence'}},
      "relevanceScore": {{faker 'datatype.number'}}
    }
    {{/repeat}}
  ],
  "metadata": {
    "totalResults": 47,
    "took": 23,
    "page": 1
  }
}

Request Example:

Requesttext
GET /api/search?q=laptop&category=electronics&minPrice=500&maxPrice=2000

Response:

Example Responsejson
{
  "query": {
    "search": "laptop",
    "category": "electronics",
    "minPrice": "500",
    "maxPrice": "2000"
  },
  "results": [
    {
      "id": 1,
      "name": "Premium Laptop",
      "category": "electronics",
      "price": "1234.56",
      "description": "High-performance laptop for professionals.",
      "relevanceScore": 95
    }
    // ... 4 more results
  ],
  "metadata": {
    "totalResults": 47,
    "took": 23,
    "page": 1
  }
}

Notes:

  • Query parameters are echoed back in the response
  • Search results include the category from the query to simulate filtering
  • Useful for testing that your app sends correct query parameters

6. Error Response Patterns

Create standardized error responses for testing error handling

Use Case:

Test error handling, validation errors, API error states

Template:

Error Response Templatejson
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request parameters",
    "details": [
      {
        "field": "email",
        "message": "Email format is invalid",
        "value": {{json 'email'}}
      },
      {
        "field": "age",
        "message": "Age must be greater than 18",
        "value": {{json 'age'}}
      }
    ],
    "timestamp": {{faker 'date.dateTime'}},
    "requestId": {{faker 'datatype.uuid'}}
  }
}

Notes:

  • Standardized error structure with code and message
  • Detailed validation errors with field-level information
  • Request tracking with UUID for debugging
  • Set HTTP status code to 400 or 422 in the response configuration

Pro Tips

  • Combine multiple template types: Mix request variables, Faker, and control structures for realistic responses
  • Use @index creatively: Start from 1, 100, or any number, and use custom step values
  • Echo query parameters: Return request data in the response to verify your app is sending correct parameters
  • Test edge cases: Create templates for error responses, empty states, and boundary conditions
  • Use the editor: The built-in editor validates your templates and provides auto-completion
  • Start simple: Build complex templates incrementally, testing each piece as you go
Template Examples - DoMock Documentation