Request Validation
Validate incoming HTTP requests against JSON schemas and custom rules. Define body, query parameter, header, and path parameter validation with configurable modes to enforce, warn, log, or disable validation.
Prerequisites
- An existing mock simulation with routes
- Understanding of JSON Schema syntax (optional but helpful)
- Basic knowledge of HTTP request components
Understanding Request Validation
Request validation allows you to:
- Define expected request structure using JSON Schema
- Validate request bodies, query parameters, headers, and path parameters
- Choose how to handle validation failures (strict, warn, log only, or disabled)
- Customize error response templates
- Track validation failures for debugging
- Ensure consumers send properly formatted requests
Setting Up Validation Schemas
Access Route Validation
- Navigate to a route in your simulation
- Click Edit Route or the gear icon
- Select the Validation or Schema tab
- Click Add Schema or Configure Validation
Define Body Schema
Create a JSON Schema for request body validation:
{
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 100
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
}
},
"required": ["name", "email"],
"additionalProperties": false
}
Define Query Parameter Schema
Validate query parameters:
{
"type": "object",
"properties": {
"page": {
"type": "integer",
"minimum": 1
},
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100
},
"filter": {
"type": "string",
"pattern": "^[a-zA-Z0-9]+$"
}
},
"required": ["page"]
}
Define Header Rules
Configure header-level validation with custom rules:
[
{
"name": "X-Api-Key",
"required": true,
"pattern": "^[a-zA-Z0-9]+$"
},
{
"name": "Authorization",
"required": true,
"pattern": "^Bearer .+$"
},
{
"name": "X-Request-Id",
"required": false,
"pattern": "^[0-9a-f-]{36}$"
}
]
Header Rule Fields:
name- Header name (case-insensitive matching)required- Whether the header must be presentpattern- Regular expression the value must match
Define Path Parameter Rules
Validate dynamic path parameters:
[
{
"name": "userId",
"required": true,
"pattern": "^[0-9a-f-]{36}$"
},
{
"name": "version",
"required": true,
"pattern": "^v[0-9]+$"
}
]
Choosing Validation Modes
Validation modes control how the mock handles validation failures:
| Mode | Behavior | Use Case |
|---|---|---|
strict | Reject invalid requests with error response | Production-ready validation |
warn | Accept request but include warning headers | Development/testing with feedback |
log_only | Accept request and log failure silently | Audit/monitoring without blocking |
disabled | Skip validation entirely | Debugging or feature flags |
Set Validation Mode for a Route
- Open route validation settings
- Select validation mode:
- Strict - Return error response
- Warn - Include X-Validation-Warning header
- Log Only - Accept but record failure
- Disabled - No validation
Set Simulation-Wide Validation Mode
Apply validation mode to all routes in a simulation:
- Open simulation settings
- Navigate to Validation Settings
- Click Set Simulation Validation Mode
- Select the mode (strict, warn, log_only, disabled)
- Confirm - applies to all routes without explicit overrides
Routes with explicit mode settings keep those settings. Only routes using the default inherit the simulation-wide setting.