Content Based Routing
If you have a native API that is hosted at two or more endpoints, you can use the Content-based routing protocol to route specific types of messages to specific endpoints. You can route messages to different endpoints based on specific values that appear in the request message.
You might use this capability, for example, to determine which operation the consuming application has requested, and route requests for complex operations to an endpoint on a fast machine. For example, if your entry protocol is HTTP or HTTPS, you can select the Content-based routing. The requests are routed according to the content-based routing rules you create. You may specify how to authenticate requests.
In API Studio, the kind Route
identifies this policy.
Example of a Content Based Routing policy:
kind: Route
apiVersion: api.webmethods.io/beta
metadata:
name: contentBasedRouting
version: 1.0
namespace: sample
spec:
default-endpoint:
$ref: default_endpoint
content-based-endpoints:
- payloadIdentifier:
- jPath: '$.customer.name'
- xpath: '$.customer.id'
namespaces:
- prefix: ''
URI: ''
- regex: '$.customer.name'
endpoint:
$ref: content_based_endpoint:1.0
---
kind: HTTPEndpoint
apiVersion: api.webmethods.io/beta
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.webmethods.io/beta
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:
Type | Description |
---|---|
kind |
|
apiVersion | Denotes the version of the API in use. |
metadata | Denotes the metadata or details of the asset type. It covers this metadata:
|
spec |
You can configure the following policy specifications:
|
To configure the default_endpoint
, you can specify:
Type | Description |
---|---|
kind |
|
apiVersion |
Denotes the version of the API in use. |
metadata |
Denotes the metadata or details of the asset type. It covers this metadata:
|
spec |
This denotes various asset properties that you can configure for the endpoint. These are the endpoint specifications that can be configured:
|
To configure the conditional_endpoints
, you can specify:
Type | Description |
---|---|
kind |
|
apiVersion |
Denotes the version of the API in use. |
metadata |
Denotes the metadata or details of the asset type. It covers this metadata:
|
spec |
This denotes various asset properties that you can configure for the endpoint. These are the endpoint specifications that can be configured:
|