Loading Small Amounts Of Data From Lumen API Time
I have an API built in lumen and I plan to consume the API json response in the frontend using a single page framework like Angular.
The problem is the response from some routes contain huge amount of data which is aprox 50000 rows as of now. I intend to send the data to the frontend in small portion depending on how much the user is using.
for example on a social site you get small chunks of posts loaded at a time and as you scroll down more post are loaded until you eventual close the application
I would like my API to do something similar. Alternatives that I have considered are
- Using the Laravel Chunk method. The problem with this method I have found that chunking does not necessarily bring small amounts of data at time, it just sub divides it and I can't use it because the server will load for a very long time if the data to be subdivided is huge as in my case and will eventually run out of memory and it is bad UX.
- Using the Laravel Paginate method. Even though this does exactly what I described above, the issue I have is that I want the data to be in list format and lazyloaded whenever a user reaches the end of a page exactly the way facebook does when you reach the last post. I don't want users to paginate to view more data. I would like the API to keep sending data depending on where it left.
What options do I have for achieving this and also is there a workaround on the options I mentioned above?
THANK YOU
Answer
So, sine the Paginate method does exactly what you need, you will need to use it. Implement an API function that will receive a starting point and an offset on the server-side.
On the client-side you do not have to display paging controls. You can instead implement a scroll
event and detect if the scrolling reached the bottom. If so, then trigger a function
(still in JS on the client-side), that will ask for the next packet of data. For this purpose, you will always need to know/find out how many records were already loaded and send that number as the starting point and your offset to the API function
we have discussed above.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms