Mocks

Intercept outbound HTTP requests from your services and return controlled responses.

When a service makes an outbound HTTP request, the interceptor sidecar checks it against all MOCK items. If a mock matches, the mock response is returned. If no mock matches, the request passes through to its real destination.

Required fields

FieldTypeDescription
type"MOCK"Item type
namestringUnique name (1-63 chars)
mockTargetstringTarget hostname to intercept (e.g., api.stripe.com)
mockPathstringURL path to match (e.g., /v1/charges, /api/*)

Optional fields

FieldTypeDefaultDescription
descriptionstringHuman-readable description (max 500 chars)
mockMethodenum*HTTP method: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, or * (any)
mockOriginstringanyService name that makes the request, or * for any
mockDelayMsintegerArtificial response delay in milliseconds
mockResponseStatusintegerHTTP response status code (100-599)
mockResponseHeadersobjectResponse headers
mockResponseBodyany JSONResponse body

Example — mocking Stripe

{
  "type": "MOCK",
  "name": "mock-stripe-charges",
  "mockMethod": "POST",
  "mockOrigin": "payment-service",
  "mockTarget": "api.stripe.com",
  "mockPath": "/v1/charges",
  "mockDelayMs": 100,
  "mockResponseStatus": 200,
  "mockResponseHeaders": { "Content-Type": "application/json" },
  "mockResponseBody": {
    "id": "ch_test_123",
    "object": "charge",
    "amount": 2000,
    "currency": "usd",
    "status": "succeeded"
  }
}

Example — mocking a failure

{
  "type": "MOCK",
  "name": "mock-stripe-failure",
  "mockMethod": "POST",
  "mockTarget": "api.stripe.com",
  "mockPath": "/v1/charges",
  "mockResponseStatus": 402,
  "mockResponseBody": {
    "error": { "type": "card_error", "message": "Your card was declined." }
  }
}

Path matching

The mockPath field supports several matching patterns:

PatternExampleMatches
Exact/v1/chargesOnly /v1/charges
Trailing wildcard/api/*Any path starting with /api/
Path variable (braces)/api/users/{userId}/api/users/123, /api/users/abc
Path variable (colon)/api/users/:idSame as above — colon syntax is converted to braces internally
Full wildcard*Any path

Query strings are ignored during path matching. Wildcards in the middle of a path (e.g., /api/*/posts) are not supported — only trailing wildcards work.

Mock precedence

When multiple mocks match the same request, the most specific mock wins. Specificity is scored by how many fields are narrowed beyond the default wildcard:

On a tie, exact paths beat path variables, and the mock defined first wins.

Alternative: top-level mocks array

Mocks can also be defined in a top-level mocks array on the definition, with shorter field names:

{
  "name": "my-definition",
  "items": [ ... ],
  "mocks": [
    {
      "name": "Stripe Create Charge",
      "method": "POST",
      "origin": "payment-service",
      "target": "api.stripe.com",
      "path": "/v1/charges",
      "responseStatus": 200,
      "responseHeaders": { "Content-Type": "application/json" },
      "responseBody": { "id": "ch_test", "status": "succeeded" }
    }
  ]
}

Field name mapping

Item fieldMocks array field
mockMethodmethod
mockOriginorigin
mockTargettarget
mockPathpath
mockDelayMsdelayMs
mockResponseStatusresponseStatus
mockResponseHeadersresponseHeaders
mockResponseBodyresponseBody