Mock 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 Mock Routing policy:
kind: Route
apiVersion: api.webmethods.io/beta
metadata:
name: api-mock-route
description:
version: 1.0
namespace: sample
tags:
- mock
spec:
mock-endpoint:
enabled: true
$ref: sample:api_mock:1.0
---
kind: MockEndpoint
apiVersion: api.webmethods.io/beta
metadata:
name: api_mock
description: This is the mocking file for Pet store API
version: 1.0
namespace: sample
tags:
- swagger
- petstore
- sample
- mock
spec:
config:
- condition: ($request.path equals v2/pet and $request.method equals GET and $request.query.<key1> equals 'test')
response:
$ref: sample:api_response:1.0
- condition: ($request.path equals v2/pet and $request.method equals POST and $request.query.<key1> equals 'test' and $request.body.<val>)
response:
$ref: sample:api_response:1.0
- condition: default
response:
$ref: sample:api_response:1.0
---
kind: MockResponse
apiVersion: api.webmethods.io/beta
metadata:
name: api_response
description: This is the mocking file for Pet store API
version: 1.0
namespace: sample
tags:
- swagger
- petstore
- sample
- mock
spec:
code: 201
headers:
- key: auth
value: <token>
data:
- contentType: application/json
content: {empid: 1}
- contentType: application/xml
content: <test></test>
To invoke the Mock 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 mock_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 specify for the
endpoint.
|
To configure the MockResponse
, 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 response. These are the mock response specifications that can be configured:
|