JSON - Pagination on Apigee Edge

Not applicable

Is it possible to do Pagination (of a JSON response) on Apigee Edge

For Example –

A backend – (that does not have any paging mechanism) - returns a JSON array of 200 items.

Can we store the response in a Cache - and then Query on the Cache – to return 10 items at a time.

(I have seen something similar done using XSL Transformation - in one of the cookbook examples, but it doesn't suggest anything for paging JSON responses.)

Solved Solved
0 7 2,700
1 ACCEPTED SOLUTION

Not applicable

So the way - I figured - I would do it is as follows : 1. Use LookUpCache

2. If LookUpCache fails - do a Service Callout (sync) -wait of it.

3. Populate Cache

4. LookUpCache again (store response in a variable)

5. Use a JavaScript policy - JSON parse the variable from LookUpCache

6. Use JSON Splice - (based on limit and offset - in queryparam)

7. Set response as the Spliced JSON.

This worked for my sample data; Please provide comments if this way can be used for pagination of a JSON response on Apigee Edge. Please let me know - any drawbacks to this approach, any modifications or better solutions.

View solution in original post

7 REPLIES 7

Not applicable

Hi @Aditya Elkunchwar,

This is very much possible. This can help to avoid going to the backend and serve the request from the Edge. However, important aspect is data size and need to be considered in the solution. What's the worst case of size of these 200 records?

Large amount of data size (depends on the size of each record) will consume the memory and may have negative impact on the performance. Other standard cache related aspects like TTL of the cache entry, invalidation of cache, etc. need to be analysed.

Cheers, Rajesh Doda

Thanks for your response. I understand "caching" and the factors related to it.

What I don't understand - is how to send only the first 10 records out of a "cached response containing 200 records". Assume - record size to be sufficiently small - to not cause any complications.

Not applicable

So the way - I figured - I would do it is as follows : 1. Use LookUpCache

2. If LookUpCache fails - do a Service Callout (sync) -wait of it.

3. Populate Cache

4. LookUpCache again (store response in a variable)

5. Use a JavaScript policy - JSON parse the variable from LookUpCache

6. Use JSON Splice - (based on limit and offset - in queryparam)

7. Set response as the Spliced JSON.

This worked for my sample data; Please provide comments if this way can be used for pagination of a JSON response on Apigee Edge. Please let me know - any drawbacks to this approach, any modifications or better solutions.

Looks good @Aditya Elkunchwar, The only suggestion I would do is - to eliminate step 1,2,3 and use a TargetEndpoint with ResponseCache.

A Targetendpoint with ResponseCache does exactly 1,2,3 - it provides better manageability of your proxy - even if you don need it now, it will come in handy in future.

4,5,6,7 would be in the response flow and should just work

can you upload source code of this task

Does any one have source code for this ?

Not applicable

Hi @Aditya Elkunchwar,

Important thing to take care is which page is currently cached. e.g. Need to make a callout when there is a request for records related to 201 onwards. Similarly logic for backward way. Use metadata to store this info.

Minor point, I guess, you meant "slice" method and not "splice" method.

Cheers, Rajesh