New Transparent capture is in preview. Record every app's traffic with no proxy configuration, on Windows, macOS and Linux. Learn more

mockedResponseAction Action

Reply to matched exchanges with a pre made response loaded from raw text, base64, or a file on disk.

Stubbing a single endpoint is one of the most useful tricks a debugging proxy can offer. mockedResponseAction lets you swap in a deterministic response without touching upstream services, which makes flaky integrations testable and broken backends survivable. Combine it with focused filters so only the calls you really want to stub are intercepted.

When to use this action

Use mockedResponseAction to return a deterministic response without ever calling the upstream. It is the right tool for stubbing out a dependency, freezing flaky third party calls, or testing client side error handling.

Typical situations include:

  • Returning a fixed JSON payload from an upstream that is slow, expensive, or rate limited.
  • Forcing a specific error code (404, 429, 500) to test client retry logic.
  • Serving a precaptured response from disk to debug a UI rendering bug.
  • Building a quick mock server inside Fluxzy without spinning up a separate process.

The action runs on the requestHeaderReceivedFromClient scope, before Fluxzy opens any connection to the upstream. The response.body.origin property selects how the body is loaded: FromString, FromImmediateArray (base64), or FromFile.

Real world examples

Return a JSON stub for a specific endpoint

Useful when you want a fast, deterministic response while developing the client.

rules:
- filter:
    typeKind: FilterCollection
    operation: And
    children:
    - typeKind: HostFilter
      pattern: api.internal.example.com
    - typeKind: PathFilter
      pattern: /v1/profile
  actions:
  - typeKind: MockedResponseAction
    response:
      statusCode: 200
      headers:
      - name: Cache-Control
        value: no-store
      body:
        origin: FromString
        type: Json
        text: '{"id":42,"plan":"pro"}'

Force a 503 to test client retry behaviour

A repeatable way to exercise error paths without waiting for the upstream to actually fail.

rules:
- filter:
    typeKind: PathFilter
    pattern: /payments/charge
  actions:
  - typeKind: MockedResponseAction
    response:
      statusCode: 503
      headers:
      - name: Retry-After
        value: 5
      body:
        origin: FromString
        type: Text
        text: 'Service temporarily unavailable'

Serve a precaptured binary response from disk

Lets you replay a real payload (an image, a PDF, a protobuf) for offline debugging.

rules:
- filter:
    typeKind: PathFilter
    pattern: /assets/banner.png
  actions:
  - typeKind: MockedResponseAction
    response:
      statusCode: 200
      headers:
      - name: Content-Type
        value: image/png
      body:
        origin: FromFile
        type: Binary
        fileName: /etc/fluxzy/mocks/banner.png

Reference

mockedResponseAction

Description

Reply with a pre-made response from a raw text or file

Evaluation scope

Evaluation scope defines the timing where this filter will be applied.

requestHeaderReceivedFromClient This scope occurs the moment fluxzy parsed the request header receiveid from client

YAML configuration name

mockedResponseAction

Settings

The following table describes the customizable properties available for this action:

Property Type Description DefaultValue
response.statusCode int32 The status code of the response
response.headers array of (name, value) Response headers
response.body.origin notSet | fromString | fromImmediateArray | fromFile Defines how the content body should be loaded
response.body.type unknown | text | json | xml | html | binary | css | javaScript | js | font | proto The body type. Use this property to avoid defining manually content-type header.This property is ignored if Content-Type is defined explicitly.
response.body.text string When Origin = fromString, the content text to be used as response body. Supports variable.
response.body.fileName string When Origin = fromFile, the path to the file to be used as response body.
response.body.contentBase64 string When Origin = fromImmediateArray, base64 encoded content of the response

Example of usage

The following examples apply this action to any exchanges

Mock a response with a raw text.

rules:
- filter:
    typeKind: AnyFilter
  actions:
  - typeKind: MockedResponseAction
    response:
      statusCode: 200
      headers:
      - name: DNT
        value: 1
      - name: X-Custom-Header
        value: Custom-HeaderValue
      body:
        origin: FromString
        type: Json
        text: '{ "result": true }'

Mock a response with a file.

rules:
- filter:
    typeKind: AnyFilter
  actions:
  - typeKind: MockedResponseAction
    response:
      statusCode: 404
      headers:
      - name: Server
        value: Fluxzy
      - name: X-Custom-Header-2
        value: Custom-HeaderValue-2
      body:
        origin: FromFile
        type: Binary
        fileName: /path/to/my/response.data

.NET reference

View definition of MockedResponseAction for .NET integration.

See also

The following actions are related to this action:

Frequently asked questions

Does Fluxzy still call the upstream when the action fires?

No. The mocked response short circuits the exchange, so the upstream connection is never opened.

How do I set the Content-Type without writing the header by hand?

Set body.type to Json, Html, Xml, JavaScript, Css, Binary, and Fluxzy fills the Content-Type for you. The header you provide explicitly always wins.

Can I use captured variables in the body?

Yes. The text body interprets Fluxzy variables, so you can echo back the request path or a header into the response.

How is this different from rejectWithMessageAction?

rejectWithMessageAction returns a short error response intended to deny the exchange. mockedResponseAction is a full fledged stub with headers, body type, and arbitrary status codes.

Learn more about Fluxzy rules