Start Here

  • Introduction
  • Quick Start

Core Features

  • Project Settings
  • Schema Builder
  • Dynamic Data
  • Conditional Logic
  • Relationships
  • Consuming your API

Integrations

  • n8n Workflows
  • Make (Integromat)
  • AI Tools

Conditional Logic

Make your API dynamic by showing, hiding, or changing data based on the incoming request.

The Context Object

When a request hits your endpoint, Mock66 captures the details and exposes them to your schema via a global object called req.

PropertyDescriptionExample Usage
req.queryURL Query Parameters (after the ?)req.query.role == 'admin'
req.bodyJSON Body payload (for POST/PUT requests)req.body.type == 'pro'
req.paramsDynamic Route Parameters (e.g., /users/:id)req.params.id == '123'

Writing Conditions

A condition is simply a JavaScript Expression that returns true or false.

  • If the result is true, the field is included in the response.
  • If the result is false (or throws an error), the field is completely removed from the JSON output.
  • Use == for loose equality to handle string/number mismatches in query params.
  • See complex examples in the JEXL documentation.

Valid Expressions:

javascript
// Simple equality
req.query.include_email == 'true'

// Logical OR / AND
req.query.role == 'admin' || req.query.role == 'editor'

// Checking existence
!!req.body.payment_method

Using the Editor

You don't need to write code files. You can attach conditions directly to any field in the Visual Builder.

1. Open Field Settings

Hover over any field row in the builder. Click the icon on the right side.

2. Enter the Expression

Find the input labeled "Conditional Logic". Paste your JavaScript expression there.

Interactive Example: Field with Logic
Demo Schema

Visual Designer

:
{ }object
:
ABCstring

Common Recipes

Role-Based Visibility

Hide sensitive fields like `revenue` unless the user is an admin.

js
req.query.role == 'admin'

Simulating Errors

Add an `error` object, but only show it if specifically requested.

js
req.query.error == 'true'

Simulating Pagination

You can mimic pagination logic using standard conditionals on items inside an array.

The Pagination Trick

Create multiple items in an array, but set conditions so they only appear for specific page numbers.

  1. Create a root array with 4 items.
  2. Items 1 & 2: Set condition to:
    !req.query.page || req.query.page == '1'
  3. Items 3 & 4: Set condition to:
    req.query.page == '2'
Now, requesting /api/users?page=2 will hide the first two items and only return the last two.

On this page

  • The Context Object
  • Writing Conditions
  • Using the Editor
  • Common Recipes
  • Simulating Pagination
Previous
Dynamic Data
Next
Relationships