Content based routing
If your API is hosted at multiple endpoints, you can use the Content based routing protocol to send requests to the correct endpoint based on the content of the request message.
This capability lets you determine which operation a consuming application has requested and route complex requests to an endpoint on a faster machine. If the entry protocol is HTTP or HTTPS, select Content based routing to route requests based on the rules you define and configure authentication for incoming requests.
In IBM API Studio, the kind
Route identifies this policy.
Example of a Content based routing policy:
kind: Route
apiVersion: api.ibm.com/v1
metadata:
name: contentBasedRouting
version: 1.0
namespace: dev
spec:
default-endpoint:
$ref: dev:default_endpoint:1.0
content-based-endpoints:
- payloadIdentifier:
xpath: '/xpath'
namespaces:
- prefix: 'ns1'
URI: 'http://uri1'
- prefix: 'ns2'
URI: 'http://uri2'
endpoint:
$ref: dev:content_based_endpoint1:1.0
- payloadIdentifier:
jPath: '/jsonpath'
endpoint:
$ref: dev:content_based_endpoint2:1.0
- payloadIdentifier:
regex: '*regex'
endpoint:
$ref: dev:content_based_endpoint3:1.0
---
kind: HTTPEndpoint
apiVersion: api.ibm.com\v1
metadata:
name: default_endpoint
version: 1.0
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: content_based_endpoint
spec:
url: http://localhost:4000/
method: GET
connectTimeout: 300
readTimeout: 200
sslConfig:
keyStoreAlias: ""
keyAlias: ""
trustStoreAlias: ""
serviceRegistryParameters:
- name: ""
value: ""
To invoke the Content based 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.
|
To configure the default-endpoint and content-based-endpoint,
use the kind: HTTPEndpoint to specify the endpoint details:
| Type | Description |
|---|---|
spec |
This denotes various asset properties that you can configure for the endpoint. These are the endpoint specifications that can be configured:
|