One of the requirements in my current project is to be able to select a target URL for a client based on certain conditions, and these conditions may have AND/OR operators and have nested conditions as well. A rudimentary cooked-up example:
if (device == 'android' || device == 'iOS') {
if ( (flag1 == 'x' && productId == 'ABC123') || (flag1 == 'y' && productId == 'EFG345') ) {
return url1;
}
}
else if (device == 'mac' || device == 'windows') {
...
}
Pretty simple if you are building this service, but our challenge is that this logic needs to be supplied to our vendors, who take care of the URL selection for specific sections of our customer base, and they all use different implementation languages - Java, Go-Lang, Python, you name it.
The question is, assuming the variables such as device, flag1, productId, etc. are already populated, is there a language agnostic way of specifying these rules, like in a JSON for example?
I looked at: Representing logic as data in JSON
and I like the suggestion to use something like:
["AND",
{"var1" : "value1"},
["OR",
{ "var2" : "value2" },
{ "var3" : "value3" }
]
]
But I don't see any standard parsers that can read this JSON and apply the rules in a specific language of choice. Are there any standard solutions out there to help with this requirement, without having multiple custom parsers and implementations that are prone to error?
P.S: We can have each of our vendor write their own snippet for this selection logic, but the challenge is the rules may change quite frequently, and we don't want to wait for several different companies to roll out code changes to their systems every time we change a rule. We also thought of writing a service and having the vendors call us, so that there is centralized access to these rules, but this means an extra network call (or have the maintain a cache and keep polling our service). Further, not all vendors are open to the idea of calling a service at the time of URL selection.