Conditional routing
This policy routes requests based on defined conditions.
If you have a native API that is hosted at two or more endpoints, you can use the condition-based protocol to route specific types of messages to specific endpoints.
In IBM API Studio, the kind
Route identifies this policy.
Example of an Conditional routing policy:
kind: Route
apiVersion: api.ibm.com/v1
metadata:
name: conditionalRouting
version: 1.0
namespace: dev
spec:
default-endpoint:
$ref: dev:default_endpoint:1.0
conditional-endpoints:
- condition: "(${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})"
endpoint:
$ref: dev:conditional_endpoint:1.0
---
kind: HTTPEndpoint
apiVersion: api.ibm.com/v1
metadata:
name: default_endpoint
version: 1.0
namespace: dev
spec:
url: http://localhost:3000/
method: GET
connectTimeout: 300
readTimeout: 200
sslConfig:
keyStoreAlias: ""
keyAlias: ""
trustStoreAlias: ""
serviceRegistryParameters:
- name: ""
value: ""
---
kind: HTTPEndpoint
apiVersion: api.ibm.com/v1
metadata:
name: conditional_endpoint
version: 1.0
namespace: dev
spec:
url: http://endpoint1/
method: GET
connectTimeout: 101
readTimeout: 102
sslConfig:
keyStoreAlias: ""
keyAlias: ""
trustStoreAlias: ""
serviceRegistryParameters:
- name: ""
value: ""
To invoke the Conditional routing policy, you can specify:
| Code view | Form view | Description |
|---|---|---|
| spec | Endpoint reference | In the form view, you can use the Add endpoint button to specify the
endpoint details. You can configure the following policy specifications:
|
To configure the default-endpoint and conditional-endpoints,
use the kind: HTTPEndpoint to specify the endpoint details:
| Code view | Form view | Description |
|---|---|---|
spec |
Endpoint reference | This denotes various asset properties that you can configure for the endpoint. These are the endpoint specifications that can be configured:
|