---
title: SwitchFilter
description: Route requests or responses to specific handlers in PingGateway based on conditions evaluated before or after processing
component: pinggateway
version: 2024.11
page_id: pinggateway:reference:SwitchFilter
canonical_url: https://docs.pingidentity.com/pinggateway/2026/reference/SwitchFilter.html
llms_txt: https://docs.pingidentity.com/pinggateway/llms.txt
docs_for_agents: https://developer.pingidentity.com/build-with-ai/docs-for-agents.md
revdate: 2026-06-02T09:47:34Z
superseded_by: https://docs.pingidentity.com/pinggateway/2026/reference/SwitchFilter.html
section_ids:
  SwitchFilter-usage: Usage
  SwitchFilter-properties: Properties
  SwitchFilter-example: Example
  SwitchFilter-moreinfo: More information
---

# SwitchFilter

Verifies that a specified condition is met. If the condition is met or no condition is specified, the request is diverted to the associated handler, with no further processing by the switch filter.

## Usage

```json
{
    "name": string,
    "type": "SwitchFilter",
    "config": {
        "onRequest": [
            {
                "condition": runtime expression<boolean>,
                "handler": Handler reference
            },
            ...
        ],
        "onResponse": [
            {
                "condition": runtime expression<boolean>,
                "handler": Handler reference
            },
            ...
        ]
    }
}
```

## Properties

* `"onRequest"`: *array of [objects](preface.html#definition-object), optional*

  Conditions to test (and handler to dispatch to, if `true`) before the request is handled.

* `"onResponse"`: *array of [objects](preface.html#definition-object), optional*

  Conditions to test (and handler to dispatch to, if `true`) after the response is handled.

* `"condition"`: *runtime expression<[boolean](preface.html#definition-boolean)>, optional*

  A flag to indicate that a condition is met:

  * `true`: The request is dispatched to the handler.

  * `false`: The request is not dispatched to the handler, and the next condition in the list is tried.

    When the last condition in the list returns `false`, the request is passed to the next filter or handler in the chain.

  Default: `${true}`

* `"handler"`: *Handler [reference](preface.html#definition-reference), required*

  The [Handler](Handlers.html) to which PingGateway dispaches the request if the associated condition yields `true`.

  Provide the name of a Handler object defined in the heap or an inline Handler configuration object.

## Example

This example intercepts the response if it is equal to 200 and executes the LoginRequestHandler. This filter might be used in a login flow where the request for the login page must go through to the target, but the response should be intercepted in order to send the login form to the application. This is typical for scenarios where there is a hidden value or cookie returned in the login page, which must be sent in the login form:

```json
{
    "name": "SwitchFilter",
    "type": "SwitchFilter",
    "config": {
        "onResponse": [
            {
                "condition": "${response.status.code == 200}",
                "handler": "LoginRequestHandler"
            }
        ]
    }
}
```

## More information

[org.forgerock.openig.filter.SwitchFilter](../_attachments/apidocs/org/forgerock/openig/filter/SwitchFilter.html)
