Is it possible to implement a pagination control for the API?

Hi all! Encountered an interesting thing. What if the number, say the news, to go with IPAS will be more than 1000 for example? From the point of view of optimization probably correct to give 20-30 for example, any one request. So. Is it possible and if so how to implement this feature to not return immediately 100,500 news, and returned in small pieces. And as in this case in the front? When scrolling pages to send a request for the next batch of news or what?
June 27th 19 at 15:03
2 answers
June 27th 19 at 15:05
Is it possible and if so how to implement this feature to not return immediately 100,500 news, and returned in small pieces.


Use LIMIT:
SELECT FROM `table` WHERE `article_id` = {ARTICLE_ID} LIMIT 5, 10

The query will return 5 records (5-10 inclusive)

When scrolling pages to send a request for the next batch of news or what?

Yes
June 27th 19 at 15:07
What you're looking for is called pagination. Accept two optional parameters: uint uint page and perPage. In the first page number and the second number of records per page, respectively. Do not forget about validation.
It seems that usually these parameters called offset and limit - Art_Christians commented on June 27th 19 at 15:10
Not necessarily, one from the other easily calculated - andre_Erdman43 commented on June 27th 19 at 15:13

Find more questions by tags APIWeb Development