Dynamic routing
This policy dynamically determines the destination for each request.
Dynamic routing selects an endpoint at runtime by evaluating conditions based on the incoming request. The routing decision is made using values from request headers or context variables, allowing the API to direct traffic to different endpoints depending on the request data or execution context.
This approach lets you direct requests to different backend services depending on request data or environment-specific settings.
In IBM API Studio, this policy is identified by
the kind Route.
Example of a Dynamic routing policy:
kind: Route
apiVersion: api.ibm.com/v1
metadata:
name: dynamicRoutingContext
version: 1.0
namespace: dev
spec:
default-endpoint:
$ref: dev:default_endpoint:1.0
dynamic-endpoints:
useContext:
$ref: dev:dynamic_endpoint_context: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: dynamic_endpoint_context
version: 1.0
namespace: dev
spec:
url: http://endpoint1/
method: GET
connectTimeout: 101
readTimeout: 102
sslConfig:
keyStoreAlias: "DEFAULT_IS_KEYSTORE"
keyAlias: "ssos"
trustStoreAlias: "DEFAULT_IS_TRUSTSTORE"
serviceRegistryParameters:
- name: ""
value: ""
To invoke the Dynamic routing policy, you can specify:
| Type | Description |
|---|---|
spec |
You can configure the following policy specifications: The
spec defines the default endpoint and the dynamic
routing options. You can configure dynamic routing by selecting an endpoint based on values
from the context or from a specific request header.
|
To configure the default_endpoint and dynamic-endpoints, you
can specify:
| Type | Description |
|---|---|
spec |
This denotes various asset properties that you can configure for the endpoint. These are the endpoint specifications that can be configured:
|