简体   繁体   English

在Rails API中,是否存在用于“分页”或“分块”大型API请求响应的标准方法?

[英]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. 我有一个带有/tasks.json终结点的Rails API,可为所有任务提供服务。
  • For large Accounts this can sometimes be close to 1,000,000 records. 对于大型帐户,有时可能接近1,000,000条记录。
  • Sending 1,000,000 records over the wire in JSON generally doesn't work due to a network timeout, etc. 由于网络超时等原因,以JSON格式通过网络发送1,000,000条记录通常不起作用。

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? 我可以轻松地“分页”发送的任务数,以便端点使用类似/tasks.json?limit=10000&page=1但是客户端如何知道发送此任务?

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. 您应该使用kaminari宝石。 It handles all requests and paginates it. 它处理所有请求并分页。 It works both on Rails Api apps and rails standard apps. 它可以在Rails Api应用程序和Rails标准应用程序上使用。 https://github.com/kaminari/kaminari https://github.com/kaminari/kaminari

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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