webMethods.io API Gateway: When To Use Routing Policies

Kasi – I think I am clear on the difference between content- and context-based. I am looking for content-based (we’re using context-based in another API). Given this sample payload:

{
  "abc" : "123x",
  "function" : "xyz",
  "foo" : "bar"
}

I want to define a rule to route to specific targets based upon the value of say, $.function. Not dynamic–the value isn’t to be part of the URL. For example:

if $.function == “xyz” route to endpoint https://abc.com/foo/bar
if $.function == “flippityfloop” route to endpoint https://southpark.com/marklar

Here is the properties pane of content-based routing in 10.5:

The documentation for this policy describes Payload Expression as “Specifies using the payload identifier to identify the client, extract the custom authentication credentials supplied in the request represented using the payload identifier, and verify the client’s identity.”

The documentation goes further to describe Expression Types and the JSONPath type: “Provide the Payload Expression that specifies the payload expression that the specified JSONPath expression type in the request has to be converted to. For example: $.name.id”

Those descriptions and the properties pane are exactly the same as those for “Identify and Authorize Application” used to extract a value that can then be matched with an application. As elaborated upon at webMethods.io API Gateway: Securing APIs using Payload Element

There, one defines how to extract the app ID value of interest from an arbitrary element in the payload. Then, assign values in the application config for the “Payload Identifier” identifier. Makes good sense there.

Content-based routing config does not seem to match the high-level description “You can route messages to different endpoints based on specific values that appear in the request message.”

What am I missing?

[Edit] I suspect what I’m missing is simply to use JSONPath filter operators although those are used to filter arrays. E.g. $.function == “xyz” as my example above. I’ll dig into that, but it would awesome if the docs and panel labels were a bit more clear…

[Edit2] Success! Using this expression did what I wanted. [?($.function==“xyz”)]

1 Like