RESTful 设计:分页集合 [英] RESTful Design: Paging Collections

查看:33
本文介绍了RESTful 设计:分页集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个 REST api,它需要从服务器端执行分页(每 x).

I am designing a REST api that needs paging (per x) enforces from the server side.

浏览任何资源集合的正确方法是什么:

What would be the right way to page through any collection of resources:

选项 1:

GET /resource/page/<pagenr>
GET /resource/tags/<tag1>,<tag2>/page/<pagenr>
GET /resource/search/<query>/page/<pagenr>

选项 2:

GET /resource/?page=<pagenr>
GET /resource/tags/<tag1>,<tag2>?page=<pagenr>
GET /resource/search/<query>?page=<pagenr>

如果是 1,我应该如何处理 GET/resource?重定向到/resource/page/0,回复有错误还是回复与/resource/page/0完全相同而不重定向?

If 1, what should I do with GET /resource? Redirect to /resource/page/0, reply with some error or reply with the exact same as /resource/page/0 without redirecting?

推荐答案

URI 的样子并不是最重要的部分.相反,您应该考虑的是它如何呈现给用户.例如,页面应该具有到下一个"页面的链接.页面和另一个指向上一个"的链接页(如果有).查看 RFC 5005 提要分页和存档

What the URI looks like is not the most important part. What you should be thinking about instead is how it is presented to the user. A page should for example have a link to the "next" page and another link to the "previous" page (if there is one). Take a look at RFC 5005 Feed Paging and Archiving

这篇关于RESTful 设计:分页集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆