I am working on a Apex REST framework that acts as an abstraction layer to make it easier for all our other systems to consume data from salesforce (i.e. consistent naming scheme for field names, abstraction for complex filters, pre-filtered lists, different representations for the same SObjects under differend endpoints, etc) compared to the standard REST Api.
However, I struggle with implementing proper pagination. The usual approach to use limit & offset as query parameters does not seem to work, since we have way over 50k records in certain SObjects, but the SOQL OFFSET only allows a maximum value of 2000.
I read about SOQL in for-Loops, which internally "utilizes SOAP query() and queryMore()", but I have not been able to implement this functionality with Apex directly.
How to implement pagination? I don't necessarily need limit/offset, if there are better patterns to utilize standard platform functionality, I would be very happy to use them.