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.
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:
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.
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"}'
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'
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
Reply with a pre-made response from a raw text or file
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
mockedResponseAction
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 |
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
View definition of MockedResponseAction for .NET integration.
The following actions are related to this action:
No. The mocked response short circuits the exchange, so the upstream connection is never opened.
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.
Yes. The text body interprets Fluxzy variables, so you can echo back the request path or a header into the response.
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.