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
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
Error Simulation
Test error handling with query parameters
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
method
HTTP method (GET, POST, etc.)path
Request pathquery
Query parameters mapData Variables
header
Request headers (lowercase)body
Parsed JSON bodyparams
Path parameters