It’s common to want to run trigger differing behaviors inside your read script based on a parameter. For example, imagine we have a table called ‘foo’ and we want to have a default path and two special operations called ‘op1’ and ‘op2’ that do something slightly different (maybe one loads a summary of the objects to reduce the amount of traffic on the wire whilst the other expands a relationship to load child records).
Here’s my approach to this:
So now, if I hit the HTTP endpoint for my table
We’ll load the records as normal, returning a JSON array. However, if we add a parameter
Then we’ll get the following response:
"this result is from operation1"
And if we hit ?operation=op2 then we’ll get:
"this result is from operation2"
And, with the script above if we hit some undeclared operation (?operation=nonsense) then we’ll go back to the default path (you may decide to throw an error).