Pagination in a REST API

xuanbao · · 722 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have built a RESTful API, but haven&#39;t yet thought about the pagination part, now, I am implementing the pagination and would like some ideas, for example, if the user does this:</p> <p>/filter?offset=10&amp;limit=10</p> <p>and later, adds a new filter, do I cache the results of the earlier filter somewhere or do a fresh DB query?</p> <p>How about usage of websockets instead of pagination?</p> <hr/>**评论:**<br/><br/>Kraigius: <pre><p>In my service I use the query string &#34;?offset=x&amp;limit=y&#34; too. I&#39;ve also seen people use &#34;?page=x&#34; without letting the users much control on the page.</p> <p>My Go service is read only and the data rarely change. It&#39;s running behind a Nginx proxy and with a CDN so everything is pretty much cached up with a long expiration timer. I didn&#39;t have to do anything special with the Etag + Last-Modified headers. I&#39;d personally prefer avoiding hitting the DB, cache is fast.</p></pre>black_anarchy: <pre><p>It&#39;s also a good idea to use local storage, if available and when possible, to save some round trips. </p></pre>synt4x: <pre><p>Offset pagination (with a SQL backend) is one of the worst culprits of API performance, especially once you have collections in the 100k&#39;s. Don&#39;t paint yourself into a corner; most people do not need arbitrary offsets. <a href="http://use-the-index-luke.com/no-offset" rel="nofollow">http://use-the-index-luke.com/no-offset</a></p></pre>FIuffyRabbit: <pre><p><a href="https://www.google.com/search?q=Pagination+in+a+REST+API&amp;oq=Pagination+in+a+REST+API&amp;aqs=chrome..69i57j69i60&amp;sourceid=chrome&amp;ie=UTF-8" rel="nofollow">https://www.google.com/search?q=Pagination+in+a+REST+API&amp;oq=Pagination+in+a+REST+API&amp;aqs=chrome..69i57j69i60&amp;sourceid=chrome&amp;ie=UTF-8</a></p></pre>thewhitetulip: <pre><p><a href="https://developers.facebook.com/blog/post/478/" rel="nofollow">https://developers.facebook.com/blog/post/478/</a></p> <p><a href="https://dev.twitter.com/rest/public/timelines" rel="nofollow">https://dev.twitter.com/rest/public/timelines</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

722 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传