1

I have on server an endpoint which returns millions of records which makes Angular app unresponsive, so I need to use paging on server side, and call the request several times synchronously.

To do that I need to send http request to get the pages one by one, so I need to send first request to GET page 1, second to GET page 2, .... etc until the server return empty response indicating that this was the last available page, then the loop should break.

How can this be done using angular http and observables?

7
  • How would this make it any more responsive if you do the same single long request in pieces in a loop? Commented Nov 16, 2021 at 23:42
  • Because I won't block the UI waiting for million of records to respond back from the server, but I will show the concatenated pages on the table one by one with each respond from the server Commented Nov 17, 2021 at 0:16
  • you can check this stackoverflow.com/questions/54390244/… Commented Nov 17, 2021 at 0:18
  • I understand the concept but what struck me is "call the request several times synchronously." So if the user was interested in the last item on the last page, they'd have to wait until it all loaded anyway. You know more about the design and usage but pulling down millions of records seems less than useful considering a user cannot possibly view such an amount of data. If the api already has paging implemented, I wonder why you wouldn't actually page it the normal way. Good luck :) Commented Nov 17, 2021 at 0:22
  • what other way I can do, can you share your ideas with me please it would be very helpful to have a second opinion Commented Nov 17, 2021 at 0:28

1 Answer 1

1

The RxJS expand operator is a good fit for recursively calling a paginated API resource

This answer to a similar (but different) question would be a good example, although you may decide not to use the reduce operator, which builds up a collection of the responses and emits them only when all have been received

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.