Pattern for collating paginated data from http.send #495
-
Many HTTP API services that might provide input to Rego policies (e.g., via Without support for recursion, is there a Rego idiom or pattern for collating data across pages of an HTTP resource collection without having to resort to a custom built-in? As a concrete example, assume you have the following partial collections:
And what we want (through the use of Rego rules and
Paginated collections on HTTP APIs are common enough I figured there may be a standard solution to the problem. Any insight? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That is true, but rarely used in policy, as evaluation time is often critical. But if it isn't – is the total number of pages known? If so I suppose you could iterate over the pages in a comprehension: collected := [item |
n := numbers.range(1, stop)
some item in http.send({"method": "GET", "url": sprintf("%s%d", [base, n])}).body.items
] Another option would be to put a tiny service in front of this API that would deal with the pagination, and have OPA served a single page. |
Beta Was this translation helpful? Give feedback.
That is true, but rarely used in policy, as evaluation time is often critical. But if it isn't – is the total number of pages known? If so I suppose you could iterate over the pages in a comprehension:
Another option would be to put a tiny service in front of this API that would deal with the pagination, and have OPA served a single page.