简体   繁体   中英

In a Rails API, is there a standard way to “paginate” or “chunk” large API requests responses?

Scenario:

  • I have a Rails API with a /tasks.json endpoint that serves all the Tasks.
  • For large Accounts this can sometimes be close to 1,000,000 records.
  • Sending 1,000,000 records over the wire in JSON generally doesn't work due to a network timeout, etc.

I can easily "paginate" the number of tasks being sent so the endpoint uses something like /tasks.json?limit=10000&page=1 but how does the client know to send this?

Is there a "standard" way to handle large requests like this and break them up naturally into chunks?

Does each client need to handle this on their end manually?

Thanks!

You should use kaminari gem. It handles all requests and paginates it. It works both on Rails Api apps and rails standard apps. https://github.com/kaminari/kaminari

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM