Cratopus icon

Mocking Plugin

The Mocking plugin allows you to simulate backend responses directly from the gateway. This is incredibly useful for:

  • Parallel Development: Front-end teams can start working before the back-end is ready.
  • Failover Testing: Simulate 5xx or 4xx errors to test client resilience.
  • Demos: Quickly create working prototypes without setting up a full backend.

⚙️ Configuration

The plugin is typically enabled for specific routes.

- urn: "urn:crate:plugin:mocking"
  name: "v1-mock-auth"
  type: "request_filter"
  active: true
  config:
    status: 200
    headers:
      "Content-Type": "application/json"
      "X-Mock-Source": "crate-gateway"
    body: |
      {
        "status": "success",
        "user_id": "usr_mock_123",
        "roles": ["admin"]
      }      

Field Definitions

Field Type Description
status int The HTTP status code to return.
headers map[string]string Map of constant headers to include in the response.
body string The literal body to return. Can be JSON, Text, etc.

🚀 Examples

1. Simulate a Service Unavailable Error

config:
  status: 503
  body: "The service is currently unavailable for maintenance."

2. Static JSON Response

config:
  status: 200
  headers:
    "Content-Type": "application/json"
  body: '{"ping": "pong"}'

[!TIP] When the Mocking plugin is active, Crate will not attempt to forward the request to any upstream servers. The response is generated instantly at the edge.