Response Rules & Conditional Responses

Create intelligent mock APIs that respond differently based on request conditions using expr-lang expressions.

How Response Rules Work

Response rules are evaluated in order for each request. The first matching rule response is returned.

Condition-Based

Match on any request attribute

Priority Order

Rules are evaluated top to bottom

Dynamic Response

Each rule can have unique response

Rule Conditions

Write conditions using expr-lang syntax to match different request attributes

Header Matching

Match requests based on HTTP headers. Perfect for API versioning, authentication states, or client identification.

Example: API Version

header["x-api-version"] == "v2"Return v2 response format

Example: Authentication

header["authorization"] contains "Bearer"Return authenticated user data

Response Configuration

Each rule can have a completely different response configuration:

Status Code

Return different HTTP status codes

200 OK
201 Created
400 Bad Request
401 Unauthorized
500 Server Error

Response Body

Different data for each rule

{
  "status": "success",
  "data": { 
    "id": "{{uuid}}", 
    "name": "{{randomName}}",
    "email": "{{randomEmail}}",
    "timestamp": "{{now}}"
  }
}

Real-World Examples

Common use cases for response rules in your mock APIs

Authentication States

Different responses based on authentication status

No Auth Header
→ 401 Unauthorized
Valid Token
→ 200 User Profile

Error Simulation

Test error handling with query parameters

?error=timeout
→ 504 Gateway Timeout
?error=server
→ 500 Internal Server Error

Best Practices

Order rules from most specific to least specific - first match wins

Test your conditions using the endpoint test feature

Use lowercase for header names (e.g., "authorization" not "Authorization")

Access nested JSON with dot notation: body.user.email

Available Context Variables

These variables are available in your condition expressions:

Request Variables

methodHTTP method (GET, POST, etc.)
pathRequest path
queryQuery parameters map

Data Variables

headerRequest headers (lowercase)
bodyParsed JSON body
paramsPath parameters