jsonResponseFilter selects exchanges whose response body is declared as JSON through the Content-Type header. It is the idiomatic selector for inspecting and rewriting REST API responses without affecting HTML pages or static assets. Pair it with any action below to tag, log or rewrite the data the server sends back.
Reach for jsonResponseFilter when a rule should apply only to responses carrying a JSON body. It is the right selector for REST and JSON-RPC APIs where you want to act on the data the server returns rather than what the client sends.
Typical situations:
The filter evaluates on the responseHeaderReceivedFromRemote scope, so the response headers are already known but the body has not yet been streamed back to the client. Combine it with statusCodeFilter or hostFilter for finer scoping.
Apply a tag to all responses with a JSON body so they group together in the Fluxzy capture view, making it easier to inspect REST API traffic.
rules:
- filter:
typeKind: JsonResponseFilter
actions:
- typeKind: ApplyTagAction
tag:
value: json-response
Force the client to refetch JSON payloads on the next request by removing the cache control headers. Useful when debugging stale data issues.
rules:
- filter:
typeKind: JsonResponseFilter
actions:
- typeKind: RemoveCacheAction
Append a line to a file for every JSON response that comes back with a 5xx status code, useful when chasing intermittent server failures.
rules:
- filter:
typeKind: FilterCollection
children:
- typeKind: JsonResponseFilter
- typeKind: StatusCodeServerErrorFilter
actions:
- typeKind: FileAppendAction
filename: /var/log/fluxzy/json-errors.log
text: "{{exchange.url}} {{exchange.statusCode}}"
Select exchanges having JSON response body. The content-type header is checked to determine if the content body is a JSON.
Evaluation scope defines the timing where this filter will be applied.
responseHeaderReceivedFromRemote This scope occurs the moment fluxzy has done parsing the response header.
jsonResponseFilter
This filter has no specific characteristic
The following table describes the customizable properties available for this filter:
| Property | Type | Description | DefaultValue |
|---|---|---|---|
| inverted | boolean | Negate the filter result | false |
The following examples apply a comment to the filtered exchange
Select exchanges having JSON response body. The content-type header is checked to determine if the content body is a JSON.
rules:
- filter:
typeKind: JsonResponseFilter
actions:
- typeKind: ApplyCommentAction
comment: filter was applied
View definition of JsonResponseFilter for .NET integration.
The following filters are related to this filter:
It inspects the response Content-Type header. Any value containing application/json matches, which covers application/json, application/json; charset=utf-8 and vendored types such as application/vnd.api+json.
No. jsonResponseFilter only checks the Content-Type header. It will not parse the body content. Use a custom .NET filter if you need payload level matching.
On the responseHeaderReceivedFromRemote scope, which fires as soon as Fluxzy finishes parsing the response headers from the upstream. The body has not yet been streamed back to the client at that point.
jsonResponseFilter checks the response Content-Type, jsonRequestFilter checks the request Content-Type. Use the response side to act on what the server returns, and the request side to act on what the client sends.