jsonRequestFilter selects exchanges whose request body declares itself as JSON through the Content-Type header. It is the idiomatic selector for REST APIs and JSON-RPC style services, and it pairs naturally with header and authentication actions. Use it whenever a rule should only run for the write side of a JSON API.
Reach for jsonRequestFilter when a rule should only apply to requests carrying a JSON payload, identified by a Content-Type of application/json or one of its variants. It is the cleanest selector for REST API traffic that uses JSON as its wire format.
Typical situations:
The filter evaluates on the requestBodyReceivedFromClient scope, so the request body has been fully received from the client before the filter fires. Combine it with methodFilter or pathFilter to scope to specific endpoints.
Attach a bearer token to all JSON requests heading to the internal API host, while leaving non-JSON traffic alone.
rules:
- filter:
typeKind: FilterCollection
children:
- typeKind: JsonRequestFilter
- typeKind: HostFilter
pattern: api.example.com
actions:
- typeKind: AddAuthorizationBearerAction
token: dev-token-123
Mark every JSON write call so they group together in the capture view, useful when auditing the mutation traffic of a single page application.
rules:
- filter:
typeKind: JsonRequestFilter
actions:
- typeKind: ApplyTagAction
tag:
value: json-request
Return a canned 415 response to every JSON request hitting an endpoint that should only accept form data, useful to validate client behavior under content negotiation.
rules:
- filter:
typeKind: FilterCollection
children:
- typeKind: JsonRequestFilter
- typeKind: PathFilter
pattern: /upload
operation: StartsWith
actions:
- typeKind: RejectWithStatusCodeAction
statusCode: 415
Select request sending JSON body. Filtering is made by inspecting value of Content-Type header
Evaluation scope defines the timing where this filter will be applied.
requestBodyReceivedFromClient This scope occurs the moment fluxzy received fully the request body from the client. In a fullstreaming mode which is the default mode, this event occurs when the full body is already fully sent to the remote server.
jsonRequestFilter
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 request header dnt: 1.
rules:
- filter:
typeKind: RequestHeaderFilter
headerName: dnt
pattern: 1
operation: Exact
actions:
- typeKind: ApplyCommentAction
comment: filter was applied
Select exchanges issued by Chrome 112 by checking User-Agent.
rules:
- filter:
typeKind: RequestHeaderFilter
headerName: User-Agent
pattern: 'Chrome/112 '
operation: Contains
actions:
- typeKind: ApplyCommentAction
comment: filter was applied
View definition of JsonRequestFilter for .NET integration.
The following filters are related to this filter:
It inspects the request 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. jsonRequestFilter only looks at the Content-Type header. It will not validate that the bytes actually parse as JSON. Use a custom .NET filter if you need payload level checks.
On the requestBodyReceivedFromClient scope. The request body has been fully received from the client when the filter runs. In full streaming mode this also means the body has already been forwarded to the upstream.
jsonRequestFilter checks the request Content-Type, jsonResponseFilter checks the response Content-Type. Use the request side to select calls by what the client sends, and the response side to select by what the server returns.