I have a situation where I calling API service for data and when displaying that data in frontend, problem is that service I calling have a lot of data so my frontend is waiting for backend to get all data at once so it take ages to load. I can't find any solutions how to pass data to frontend without waiting all values to return and do it value by value? Currently I'm using public async Task
, but this approach waiting for all data to comeback before passing it.
Asked
Active
Viewed 226 times
0

Jules
- 85
- 1
- 12
-
1If there's a sensible divisor for the data, you could break it up into a few different web requests? – Andrew Corrigan Dec 13 '21 at 11:02
-
Take a look at [IAsyncEnumerable
](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=net-6.0) and [read this article](https://anthonychu.ca/post/async-streams-dotnet-core-3-iasyncenumerable/) could be help – Ibram Reda Dec 13 '21 at 11:10 -
This is a frontend problem, it should request multiple smaller chunks of data and show those incrementally, not all at once. Check out [paginated queries)https://stackoverflow.com/q/2380413/9363973) on how to implement such a thing – MindSwipe Dec 13 '21 at 11:14
-
Maybe it will help someone https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/generate-consume-asynchronous-stream – Jules Dec 13 '21 at 12:49
1 Answers
0
What we did we split our call in two calls. First we called API for id and loaded our page. We not fetched all data so it loaded fast. Second we called API for each id we get and just added data to object from first call. We use data from calls for dropdown element so till second call were finished we still can display object id in dropdown.

Jules
- 85
- 1
- 12